GATE Computer ScienceVery hardGATE CS (PYQ pattern)
An undirected unweighted graph has edges 1-2, 1-3, 2-4, 2-5, 3-4, 3-6, 4-7, 5-7, 6-7, 6-8, 7-9, 8-9. Using BFS from vertex 1, what is the distance to vertex 9 and the number of distinct shortest paths from 1 to 9?
- A. distance 4, 4 paths
- B. distance 4, 5 paths
- C. distance 5, 5 paths
- D. distance 4, 8 paths
Correct answer: B. distance 4, 5 paths
BFS layers: {1}, {2,3}, {4,5,6}, {7,8}, {9}. Path counts propagate additively: 4 gets 2, 5 gets 1, 6 gets 1, 7 gets 4, 8 gets 1, so 9 gets 5.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- A directed graph on vertices 1..4 has edges 1->2, 1->3, 2->3, 2->4, 3->1, 3->4, 4->1, 4->2. How many walks of length exactly 4 (edges…
- An undirected graph has 14 vertices, 20 edges and exactly 3 connected components. DFS is restarted from an unvisited vertex until all…
- A complete binary tree stored in an array has 1000 nodes. What is its height (a single node has height 0) and how many nodes are at the…
- A binary tree with 25 nodes has two pointer fields per node. How many of these 50 fields hold NULL, and how many hold NULL if the tree is…
- A circular queue of capacity 10 (array indices 0..9) keeps front and rear indices; front is the index of the first item and rear is the…
- Convert the infix expression a - b c / d + e (f - g) / h (all binary operators left-associative; and / bind tighter than + and -) to…