Question 71
HardWhat is the 'exchange argument' used for?
- A.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Data Structures and Algorithms
What is the 'exchange argument' used for?
Trading items in knapsack
Proving a greedy algorithm optimal by showing any optimal solution can be changed to the greedy one without loss
Exchanging keys in hashing
Swapping array elements
Sign up free to see the answer and a step-by-step explanation.
Fractional knapsack: capacity 50, items (value, weight) (60, 10), (100, 20), (120, 30). What is the maximum value?
160
220
240
180
Sign up free to see the answer and a step-by-step explanation.
Why does greedy fail for 0/1 knapsack with capacity 50 and items (60, 10), (100, 20), (120, 30)?
It doesn't fail
Greedy by ratio takes the first two (160 value, 30 weight) and can't fit the third, but 100 + 120 = 220 is better
Greedy gives 240
Items can't be split in any problem
Sign up free to see the answer and a step-by-step explanation.
Dijkstra's algorithm is greedy. Which choice does it make at each step?
It picks the vertex with the most edges
It picks a random vertex
It finalises the unvisited vertex with the smallest tentative distance
It picks the cheapest edge anywhere
Sign up free to see the answer and a step-by-step explanation.
Interval partitioning: lectures [9, 10.5], [9, 12.5], [9, 10.5], [11, 12.5], [11, 14], [13, 14.5], [13, 14.5], [14, 16.5], [15, 16.5], [15, 16.5]. How many rooms are needed?
4
2
5
3
Sign up free to see the answer and a step-by-step explanation.
What is the greedy choice in Kruskal's algorithm?
Add the edge closest to the start vertex
Add edges in input order
Add the most expensive edge
Add the cheapest edge that doesn't create a cycle
Sign up free to see the answer and a step-by-step explanation.
Minimising the sum of completion times on one machine is achieved by:
Longest processing time first
Shortest processing time first
Earliest deadline first
Random order
Sign up free to see the answer and a step-by-step explanation.
Minimising the maximum lateness with deadlines on one machine is achieved by:
Earliest deadline first
Highest profit first
Longest job first
Shortest job first
Sign up free to see the answer and a step-by-step explanation.
Why does the greedy 'nearest neighbour' heuristic not solve the travelling salesman problem optimally?
Locally cheapest choices can force very expensive edges later
It always gives the optimum
It is too slow
It visits cities twice
Sign up free to see the answer and a step-by-step explanation.
Which property must hold for a greedy algorithm to be correct, besides optimal substructure?
Overlapping subproblems
Negative weights
A sorted input
The greedy-choice property
Sign up free to see the answer and a step-by-step explanation.