Data Structures & AlgorithmsHardGATE CS · Product-company placement
A rod of length 8 can be cut into integer pieces; a piece of length i sells for p(i) with p(1..8) = 2, 6, 12, 16, 17, 19, 21, 23. What is the maximum revenue?
- A. 32
- B. 30
- C. 23
- D. 33
Correct answer: A. 32
r(j) = max over first piece i of p(i) + r(j − i); r(8) = 32. Repeatedly cutting the best price-per-length piece (greedy) gives only 30.
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
- A tree on vertices 1–10 has edges 2–1, 3–2, 4–1, 5–2, 6–4, 7–3, 8–6, 9–7, 10–9. What is the size of a minimum DOMINATING set (every vertex…
- A simple undirected graph has 14 vertices and exactly 2 connected components. What is the maximum possible number of edges?
- How many structurally different binary trees with 7 nodes have height EXACTLY 5 (height = edges on the longest root-to-leaf path)?
- Keys 72, 29, 21, 18, 28, 16, 23, 33, 25, 67 are inserted in order into an empty AVL tree. Counting a double rotation as two single…
- DFS runs on the directed graph with adjacency lists A: BG; B: FG; C: AEFG; D: C; E: A; F: A; G: –, starting at A, scanning lists in the…
- A tree on vertices 1–8 has edges 2–1, 3–2, 4–2, 5–2, 6–2, 7–4, 8–3. What is the sum of the distances (in edges) over all unordered pairs…