Data Structures and Algorithms - Graph Algorithm

17. The Breadth First Search algorithm has been implemented using the queue data structure. One possible order of visiting the nodes of the following graph is

  • Option : C
  • Explanation :
    Applying BFS Algorithms
    Starting from Q
    Queue Q
    Making Q’s child’s status 1.
    Queue
    Q| M| N| P
    Making M’s child 1 (which are not 1)
    Status
    QMNOPR
    211 1 
    221 11
    222111
    Q| M| N| P| R
    Making N’s Child 1
    Q| M| N| P| R| O
    (other are already 1)
Cancel reply
Cancel reply

18. Breadth First Search (BFS) is started on a binary tree beginning from the root vertex. There is a vertex t at a distance four from the root. If t is the n-th vertex in this BFS traversal, then the maximum possible value of n is

  • Option : D
  • Explanation :
    Maximum possible value of n for which we have complete tree and our 't' node is the last leaf node at height 4.
    So, the maximum possible value of n
    = 1 + 2 + 4 + 8 + 16
    = 31
Cancel reply
Cancel reply