GATE Computer ScienceVery hardGATE CSE · UGC NET
A directed graph on vertices 1–8 has adjacency lists 1:[2,5]; 2:[3,6]; 3:[4,1]; 4:[2,7]; 5:[6,4]; 6:[7]; 7:[5,8]; 8:[3,6]. DFS starts at vertex 1 and always scans adjacency lists left to right. How many (back edges, forward edges, cross edges) does it find, as a triple?
- A. (5, 2, 1)
- B. (6, 2, 0)
- C. (5, 3, 0)
- D. (4, 2, 2)
Correct answer: A. (5, 2, 1)
DFS gives 7 tree edges (all 8 vertices reached from 1); classifying the other edges by discovery/finish times gives 5 back, 2 forward and 1 cross.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- Strings X = ABCBDABA and Y = BDCABAB are given. How many distinct longest common subsequences (distinct as strings) do they have?
- Words car, card, care, cart, cat, dog, door, dot, dove, do, cargo, carbon, catalog, cat are inserted into an initially empty trie (a…
- A B-tree of order 5 (each node holds at most 4 keys) is built by inserting 1, 2, 3, …, 60 in increasing order. When a node overflows to 5…
- How many different arrays A[1..9] that are permutations of {1,…,9} satisfy the min-heap property (A[i] ≥ A[⌊i/2⌋] for every i ≥ 2)?
- What is the minimum number of comparisons needed in the worst case to find both the maximum and the minimum of 101 distinct numbers using…
- The KMP failure (prefix) function π[i] of pattern P = "abaabaabaabab" gives, for each prefix P[0..i], the length of its longest proper…