Algorithms · Dynamic programming and state design
Given an undirected graph with up to five million vertices, produce exactly the…
Problem
Given an undirected graph with up to five million vertices, produce exactly the preorder, postorder, parent array, and subtree sizes defined by recursive depth-first search that starts at vertex \(1\) and examines neighbors in increasing order. Only vertices reachable from vertex \(1\) are included in the two orders; every unreachable vertex has parent \(0\) and subtree size \(0\). Program recursion is prohibited, and auxiliary memory beyond the graph representation and output arrays is limited to \(O(n)\) machine words. The input satisfies \(1\le n\le 5{,}000{,}000\) and \(0\le m\le 8{,}000{,}000\).
Hint
** A recursive call remembers both its vertex and where its neighbor loop should resume.
Check your work
Work the problem yourself first. Then open it in Training to check your answer and read the full worked solution.
The answer check and full solution for this problem come with ProofAnvil Practice membership ($19 USD monthly). See membership. Or start with the free Algorithms sample problem: Try the free sample problem.
More Algorithms practice problems
- Let all logarithms have base 2, and let all functions have domain the positive integersCorrectness proofs and asymptotic complexity
- There are n jobs in fixed order with positive integer sizes s_1,…,s_n, and d≥1…Correctness proofs and asymptotic complexity
- Two disjoint color classes contain r≥1 red and b≥1 blue planar pointsDivide-and-conquer algorithms
- Using only comparisons, return both minimum and maximum among n≥1 distinct keysDivide-and-conquer algorithms
- Consider the invalid coding rule that repeatedly combines the two partial trees of…Greedy algorithms and exchange proofs
- The n vertices of a cycle are numbered 1,…,n, and vertex i has an integer weightGreedy algorithms and exchange proofs
- Prim’s algorithm starts at an arbitrary root and repeatedly adds a minimum-weight edge…Dynamic programming and state design
- Let T[0..n-1] be a text and P[0..m-1] a pattern over the same alphabet, where 1≤ m≤ nGraph optimization and traversal algorithms
- Consider SET COVER parameterized by the universe size p=|U|, while the number m of…Reductions, NP-completeness, and approximation