Data Structures & AlgorithmsModerateTCS NQT · Graphs
An undirected graph has edges A-B, A-C, B-D, B-E, C-E, C-F, D-G, E-G, F-G. Neighbours are always visited in alphabetical order. What is the breadth-first traversal order starting from A?
- A. A B D G E C F
- B. A B C D E F G
- C. A B C D E G F
- D. A C B F E D G
Correct answer: B. A B C D E F G
BFS visits A, then its neighbours B and C, then D, E (from B), F (from C), and finally G.
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 tree has inorder traversal D B E A F C and postorder traversal D E B F C A. What is its preorder traversal?
- How many structurally different binary search trees can be built from 5 distinct keys?
- A DAG has edges A->C, A->D, B->D, C->E, D->E, D->F, E->G, F->G. Using Kahn's algorithm and always removing the alphabetically smallest…
- In the directed graph with edges S->A (4), S->B (1), B->A (2), A->C (5), B->C (8), B->D (10), C->D (2), C->T (6), D->T (3), what is the…
- A connected undirected graph has 9 vertices and 14 edges. What is the minimum number of edges that must be removed to turn it into a…
- Keys 10, 20, 30, 40, 50, 25 are inserted in this order into an empty AVL tree. What is the preorder traversal of the final tree?