2080 12

BIT201 ยท 2080 ยท 5 marks

Write short notes on a.) Doubly circular linked list Write short notes on b.) Breadth first Search [2.5+2.5]

Write short notes on a.) Doubly circular linked list Write short notes on b.) Breadth first Search [2.5+2.5]

Data Structures and AlgorithmsChapter 4: Linked ListsDoubly circular linked list operations

Quick answer

A Doubly Circular Linked List is a type of linked list that combines the properties of both a doubly linked list and a circular linked list.

Short Notes

a.) Doubly Circular Linked List

Structure of Each Node

Each node contains three fields:

[ PREV | DATA | NEXT ]
  • PREV: Pointer to the previous node
  • DATA: The actual data stored
  • NEXT: Pointer to the next node

Key Properties

  • Every node has a pointer to both its next and previous node.
  • The last node's NEXT pointer points back to the first node.
  • The first node's PREV pointer points back to the last node.
  • There is no NULL pointer in the list.

Diagram

  +-------+    +-------+    +-------+
  |  10   | <->|  20   | <->|  30   |
  +-------+    +-------+    +-------+
      ^                          |
      |__________________________|

Advantages

  • Traversal is possible in both directions (forward and backward).
  • Insertion and deletion are easier compared to singly linked lists.
  • Starting from any node, the entire list can be traversed.
  • No need to handle NULL; traversal stops when we return to the starting node.

Disadvantages

  • Requires extra memory for the PREV pointer.
  • Implementation is more complex than singly linked lists.

Applications

  • Used in music players (next/previous song).
  • Used in browser history (forward/backward navigation).
  • Implementation of deques (double-ended queues).

b.) Breadth First Search (BFS)

Breadth First Search (BFS) is a graph/tree traversal algorithm that explores all nodes level by level, starting from a given source node.

Key Idea

  • Visit all neighbors of a node before moving to the next level.
  • Uses a Queue (FIFO) data structure to keep track of nodes to visit.
  • Uses a visited array to avoid revisiting nodes.

Algorithm Steps

  1. Start from the source node, mark it as visited, and enqueue it.
  2. Dequeue a node from the front of the queue.
  3. Visit all unvisited adjacent nodes, mark them visited, and enqueue them.
  4. Repeat steps 2-3 until the queue is empty.

Pseudocode

BFS(Graph, start):
    Create a Queue Q
    Mark start as visited
    Enqueue start into Q

    while Q is not empty:
        node = Dequeue(Q)
        print node
        for each neighbor of node:
            if neighbor is not visited:
                mark neighbor as visited
                Enqueue(neighbor)

Example

Consider the graph:

    1
   / \
  2   3
 / \
4   5

BFS Traversal starting from node 1:

StepDequeueQueue AfterVisited
11[2, 3]1
22[3, 4, 5]1,2,3
33[4, 5]1,2,3
44[5]1,2,3,4
55[]1,2,3,4,5

Output: 1 -> 2 -> 3 -> 4 -> 5

Characteristics

PropertyValue
Data Structure UsedQueue
Time ComplexityO(V + E)
Space ComplexityO(V)
Traversal OrderLevel by Level

Applications

  • Shortest path finding in unweighted graphs.
  • Web crawlers for indexing pages.
  • Social networking (finding friends within k distance).
  • Cycle detection in graphs.

Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.