Question 41
MediumWhy does the greedy rule 'pick the shortest activity first' fail for activity selection?
- 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
Why does the greedy rule 'pick the shortest activity first' fail for activity selection?
It needs sorting by start time
A short activity can overlap two others that could both have been chosen
It always works
Short activities finish last
Sign up free to see the answer and a step-by-step explanation.
Kruskal's algorithm sorts edges by weight and adds each edge if it does what?
Connects to the last vertex added
Has the smallest weight from the source
Doesn't form a cycle with the edges already chosen
Is a bridge
Sign up free to see the answer and a step-by-step explanation.
How does Prim's algorithm grow the minimum spanning tree?
By adding the cheapest edge anywhere
By running BFS
From one vertex, always adding the cheapest edge leaving the tree
By removing the most expensive edges
Sign up free to see the answer and a step-by-step explanation.
Edges: A–B 1, B–C 4, A–C 3, C–D 2, B–D 5. What is the weight of the minimum spanning tree?
6
8
10
7
Sign up free to see the answer and a step-by-step explanation.
With coins {1, 5, 6, 9}, the greedy method makes 11 as 9 + 1 + 1. What is the optimal number of coins?
4
2 (5 + 6)
1
3
Sign up free to see the answer and a step-by-step explanation.
Huffman coding: symbols A 45, B 13, C 12, D 16, E 9, F 5. Which two are merged first?
A and B
F and E
D and E
C and B
Sign up free to see the answer and a step-by-step explanation.
Why do Huffman codes never need separators between codewords?
They are stored in a table
They use a special end symbol
They are prefix-free: no codeword is the prefix of another
All codes have the same length
Sign up free to see the answer and a step-by-step explanation.
What is the greedy choice for minimising the total waiting time when serving n customers with known service times on one counter?
Serve in arrival order
Serve randomly
Serve the shortest service times first
Serve the longest first
Sign up free to see the answer and a step-by-step explanation.
Which problem does NOT have a correct greedy solution in general?
Activity selection
Minimum spanning tree
Fractional knapsack
0/1 knapsack
Sign up free to see the answer and a step-by-step explanation.
In the 'jump game', each element is the maximum jump from that index. What does a greedy scan track?
The smallest element
The farthest index reachable so far
The sum of all jumps
The number of zeros
Sign up free to see the answer and a step-by-step explanation.