Bird
Raised Fist0

Given the final DFS postorder stack: [3,2,1] after reversing, and visited map showing all nodes marked True, which original input org sequence and seqs could produce this state?

hard🔄 Reverse Engineer Q9 of Q15
Topological Sort - Sequence Reconstruction (Unique Topo Order)
Given the final DFS postorder stack: [3,2,1] after reversing, and visited map showing all nodes marked True, which original input org sequence and seqs could produce this state?
Aorg = [3,2,1], seqs = [[1,2],[2,3]]
Borg = [1,2,3], seqs = [[1,2],[2,3]]
Corg = [3,2,1], seqs = [[3,2],[2,1]]
Dorg = [1,2,3], seqs = [[3,2],[2,1]]
Step-by-Step Solution
Solution:
  1. Step 1: Interpret stack order

    Stack reversed is [1,2,3], so postorder was [3,2,1]. This means edges go from 3->2 and 2->1.
  2. Step 2: Match org and seqs

    Only org = [1,2,3] with seqs = [[3,2],[2,1]] matches edges 3->2 and 2->1 producing reversed stack [3,2,1].
  3. Final Answer:

    Option D -> Option D
  4. Quick Check:

    Edges and stack order consistent with org = [1,2,3], seqs = [[3,2],[2,1]] [OK]
Quick Trick: Postorder reversed matches org order [OK]
Common Mistakes:
MISTAKES
  • Confusing org order with postorder stack
Trap Explanation:
PITFALL
  • Candidates fail to reverse postorder or misinterpret edge directions.
Interviewer Note:
CONTEXT
  • Tests deep understanding of DFS postorder and input-output relation.
Master "Sequence Reconstruction (Unique Topo Order)" in Topological Sort

3 interactive learning modes - each teaches the same concept differently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Topological Sort Quizzes