Professional Documents
Culture Documents
1. [CLRS 23.2-4] Suppose that all edge weights in a graph are integers in the range 1 to j j.
How fast can you make Kruskal's algorithm run? What if the edge weights are integers
in the range from 1 to for some constant ?
Solution: Kruskal's algorithm sorts edges in nondecreasing order by weight. If the edge
weights are integers in the range 1 to j j, we can use Counting-Sort to sort the edges
in ( + ) time (recall Counting-Sort correctly sorts integers in the range 0 to in
( + ) time). Then Kruskal's algorithm will run in ( + + log ) = ( + log )
time.
If the edge weights are integers in the range from 1 to for some constant , we can
use Counting-Sort to sort the edges in ( + ) time and Kruskal's algorithm will
run in ( + + log ) time.
2. [CLRS 23-4]
V
O V
O E
O W
Solution:
(a)
e = S
e = S
O E
O V
O E
E V
O E
w
1
The MST of would have edges ( ) and ( ) with weight 3. Since MaybeMST-B takes edges in arbitrary order, it could add edges (
) and ( ) to ,
then try to add ( ) which forms a cycle, then return (weight 5).
G
w; u
v; w
u; v
w; u
v; w
u; v
u v
O V
O E
O V
O V
O V
O V
T
O V
O V
O EV