Data Structures & AlgorithmsHardProduct-company MCQ pattern
Each job takes 1 unit of time; only one job runs at a time. Jobs (deadline, profit): J1 (2, 100), J2 (1, 19), J3 (2, 27), J4 (1, 25), J5 (3, 15). What is the maximum total profit?
- A. 142
- B. 140
- C. 127
- D. 152
Correct answer: A. 142
Greedy by profit: J1 takes slot 2, J3 (deadline 2) takes slot 1, J4 and J2 find no free slot, J5 takes slot 3: 100 + 27 + 15 = 142. 152 = 100 + 27 + 25 would need three jobs finished by time 2, which is impossible.
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
- Characters a, b, c, d, e occur 4, 7, 9, 12 and 20 times. With an optimal Huffman code, how many bits are needed to encode the whole text?
- Bellman–Ford from A relaxes the directed edges in the fixed order C→D (2), B→C (3), A→B (4), A→C (9), B→D (7). After the FIRST full pass…
- A directed graph has edges 1→2, 2→3, 3→1, 3→4, 4→5, 5→6, 6→4, 6→7, 7→8. How many strongly connected components does it have?
- An undirected graph has edges 1–2, 2–3, 3–1, 3–4, 4–5, 5–6, 6–4, 6–7. How many articulation points (vertices whose removal disconnects the…
- What is the time complexity of g(n)? python def g(n): if n <= 1: return for i in range(n): pass # O(1) g(n // 2) g(n // 2) g(n // 2)
- 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…