Data Structures & AlgorithmsHardProduct-company MCQ pattern
How many of these statements about DFS are correct? (i) In DFS of an undirected graph, every non-tree edge is a back edge (there are no cross edges). (ii) A directed graph has a cycle if and only if its DFS finds a back edge. (iii) Listing vertices in decreasing order of DFS finish time gives a topological order of a DAG. (iv) DFS on an adjacency matrix runs in O(V + E).
- A. Only one
- B. Only two
- C. Only three
- D. All four
Correct answer: C. Only three
(i), (ii) and (iii) are true. (iv) is false: with an adjacency matrix every vertex scans a whole row of V entries, so DFS takes O(V²); O(V + E) needs adjacency lists.
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
- Keys are inserted into an empty BST in the order 45, 15, 79, 90, 10, 55, 12, 20, 50. What is the postorder traversal? python def insert(t…
- For the same kind of BST, what is the height (edges on the longest root-to-leaf path) after inserting 1, 2, 3, 4, 5, 6, 7 in order, versus…
- A max-heap is built with heapify on the array below (0-based, children 2i+1 and 2i+2). What is the resulting array? python def sift(a, i…
- From the max-heap [50, 30, 40, 10, 20, 35, 25], delete the maximum once. What is the array? python import heapq h = [-x for x in [50, 30…
- What is printed? (count leaves, internal nodes and full nodes of a binary tree) python T = {1: (2, 3), 2: (4, None), 3: (5, 6), 4: (None…
- A binary tree has preorder A B D E C F G and inorder D B E A F C G. What is its postorder? python def post(pre, ino): if not pre: return…