Data Structures & AlgorithmsModerateGATE CS
An undirected graph has edges A–B, A–D, A–H, B–G, B–H, C–D, C–E, D–E, E–H, F–H. BFS starts at A and always scans neighbours in alphabetical order. In what order are the vertices visited?
- A. A B G H E C D F
- B. A B D H G C E F
- C. A H F E D C B G
- D. A B D H C E F G
Correct answer: B. A B D H G C E F
BFS dequeues level by level, and within a level in the order vertices were enqueued (which depends on their parents, not on alphabetical order): A B D H G C E F.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- A binary search tree holds exactly the keys 28, 41, 46, 47, 55, 66, 96, 99. Which ONE of the following sequences can be its PREORDER…
- The weighted undirected graph A–B (3), A–C (5), A–E (22), B–D (18), B–F (16), C–D (8), C–F (2), E–F (26) has a unique MST. What is the…
- The connected undirected graph with edges A–C, A–F, B–C, B–D, B–G, B–H, C–D, C–F, D–E, D–G, F–H, G–H must be walked so that every edge is…
- DFS on the directed graph with adjacency lists A: CDG; B: –; C: –; D: BCF; E: –; F: CE; G: CE starts at A (scanning lists in the order…
- What is the length of the longest BITONIC subsequence (strictly increasing then strictly decreasing; either part may be empty) of [19, 10…
- Keys 32, 44, 47, 53, 93, 54, 12, 22, 68, 97 are inserted into an empty AVL tree (giving preorder 53, 44, 22, 12, 32, 47, 68, 54, 93, 97)…