GATE Computer ScienceVery hardGATE CS (PYQ pattern)
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?
- A. 14
- B. 29
- C. 42
- D. 21
Correct answer: D. 21
Count linear extensions: brute force over the 7! orderings that respect every edge gives 21.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- 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…
- An array A[-2..5][1..6][0..3] of 4-byte elements has base address 1000 (address of A[-2][1][0]). What is the address of A[3][4][2] in…