GATE Computer ScienceVery hardGATE CS (PYQ pattern)
A directed graph has adjacency lists (visited in the order listed): A: B, C; B: D, E; C: E, F; D: G; E: D, H; F: H, B; G: none; H: G, A. DFS starts at A, and the discovery and finish times use one counter that increments on every discovery and every finish (so times run from 1 to 16). How many back edges and how many cross edges does the DFS find, and what is the finish time of C?
- A. 2 back, 5 cross, f(C) = 15
- B. 1 back, 6 cross, f(C) = 13
- C. 1 back, 5 cross, f(C) = 15
- D. 1 back, 4 cross, f(C) = 16
Correct answer: C. 1 back, 5 cross, f(C) = 15
Run DFS in list order: discovery times {'A': 1, 'B': 2, 'D': 3, 'G': 4, 'E': 7, 'H': 8, 'C': 12, 'F': 13}, finish times {'G': 5, 'D': 6, 'H': 9, 'E': 10, 'B': 11, 'F': 14, 'C': 15, 'A': 16}. An edge to a gray vertex is a back edge, to a black vertex with earlier discovery a cross edge.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- A DAG on vertices 1..7 has edges 1->2, 1->3, 2->4, 3->4, 3->5, 4->6, 5->6, 7->5. How many distinct topological orderings does it have?
- Union-find on elements 1..12 (initially separate) uses union by size (the root of the larger set becomes the parent; on a tie the root of…
- A 3-ary max-heap with 100 elements is stored in a 0-indexed array (the children of i are 3i + 1, 3i + 2, 3i + 3). How many leaves does it…
- Build-heap (bottom-up, max-heap) is run on [3, 9, 2, 1, 4, 5, 8, 7, 6, 10, 12, 11]. In each sift-down step the larger of the element and…
- A dynamic array starts with capacity 4. When an append finds it full, it allocates capacity c + c / 2 (integer division), copies every…
- The words tea, ten, to, inn, in, i, ted, tent, tenant, tens, ton are inserted into an initially empty trie (one node per character, root…