Data Structures & AlgorithmsHardGATE CS · TCS NQT · Product Company SDE
An undirected graph has adjacency lists A:BDE B:AC C:BE D:AF E:ACF F:DE. Neighbours are always explored in alphabetical order. Which is the BFS visiting order starting at A?
- A. ADBECF
- B. ABDECF
- C. ABCEFD
- D. FCEDBA
Correct answer: B. ABDECF
BFS explores level by level with a queue, taking neighbours in alphabetical order, giving ABDECF.
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
- An undirected graph has adjacency lists A:BCDE B:AC C:ABE D:AG E:ACF F:EH G:DH H:FG. Neighbours are always explored in alphabetical order…
- A max-heap is built by inserting 23, 96, 77, 61, 84, 26, 70, 72 one by one (sift-up on each insert). After one extract-max (move the last…
- An undirected graph has edges (u–v: weight) A–B:9, A–C:14, A–D:11, A–E:8, C–E:2, B–D:9. What is the weight of its minimum spanning tree?
- A min-heap is built by inserting 66, 44, 32, 55, 85, 62 one by one (sift-up on each insert). After one extract-min (move the last element…
- An undirected graph has adjacency lists A:BCG B:ACEF C:ABDEG D:C E:BC F:B G:AC. Neighbours are always explored in alphabetical order…
- A DAG has edges A→B, B→C, B→D, C→E, A→F, A→D, D→F. Using Kahn's algorithm (always picking the smallest-labelled vertex among those…