Selected Solutions for Chapter 26: Maximum Flow
Solution to Exercise 26.2-11
For any two vertices u and in G , we can dene a ow network Gu consisting of the directed version of G with s D u, t D , and all edge capacities set to 1. (The ow network Gu has V
Selected Solutions for Chapter 24: Single-Source Shortest Paths
Solution to Exercise 24.1-3
If the greatest number of edges on any shortest path from the source is m, then the path-relaxation property tells us that after m iterations of B ELLMAN -F ORD, e
Selected Solutions for Chapter 23: Minimum Spanning Trees
Solution to Exercise 23.1-1
Theorem 23.1 shows this. Let A be the empty set and S be any set containing u but not .
Solution to Exercise 23.1-4
A triangle whose edge weights are all equal is a grap
Selected Solutions for Chapter 22: Elementary Graph Algorithms
Solution to Exercise 22.1-7
BB T .i; j / D
X
e 2E
T bie bej D
X
e 2E
bie bje
If i D j , then bi e bje D 1 (it is 1 1 or . 1/ . 1/) whenever e enters or leaves vertex i , and 0 otherwise. If i
Selected Solutions for Chapter 21: Data Structures for Disjoint Sets
Solution to Exercise 21.2-3
We want to show that we can assign O.1/ charges to M AKE -S ET and F IND -S ET and an O.lg n/ charge to U NION such that the charges for a sequence of these o
Selected Solutions for Chapter 17: Amortized Analysis
Solution to Exercise 17.1-3
Let ci D cost of i th operation. ( i if i is an exact power of 2 ; ci D 1 otherwise : Operation 1 2 3 4 5 6 7 8 9 10 : : : Cost 1 2 1 4 1 1 1 8 1 1 : : :
n operations cost
n
Selected Solutions for Chapter 16: Greedy Algorithms
Solution to Exercise 16.1-4
Let S be the set of n activities. The obvious solution of using G REEDY-ACTIVITY-S ELECTOR to nd a maximum-size set S1 of compatible activities from S for the rst lecture hal
Selected Solutions for Chapter 15: Dynamic Programming
Solution to Exercise 15.2-5
Each time the l -loop executes, the i -loop executes n l C 1 times. Each time the i -loop executes, the k -loop executes j i D l 1 times, each time referencing m twice. Thu
Selected Solutions for Chapter 14: Augmenting Data Structures
Solution to Exercise 14.1-7
Let A1 : : n be the array of n distinct numbers. One way to count the inversions is to add up, for each element, the number of larger elements that precede it in the
Selected Solutions for Chapter 13: Red-Black Trees
Solution to Exercise 13.1-4
After absorbing each red node into its black parent, the degree of each node black node is
2, if both children were already black, 3, if one child was black and one was red,
Selected Solutions for Chapter 12: Binary Search Trees
Solution to Exercise 12.1-2
In a heap, a nodes key is both of its childrens keys. In a binary search tree, a nodes key is its left childs key, but its right childs key. The heap property, unlike the b
Selected Solutions for Chapter 11: Hash Tables
Solution to Exercise 11.2-1
For each pair of keys k; l , where k l , dene the indicator random variable Xkl D I fh.k/ D h.l/g. Since we assume simple uniform hashing, Pr fXkl D 1g D Pr fh.k/ D h.l/g D 1=m, an
Selected Solutions for Chapter 9: Medians and Order Statistics
Solution to Exercise 9.3-1
For groups of 7, the algorithm still works in linear time. The number of elements greater than x (and similarly, the number less than x ) is at least l m 2n 1n 2 4 8
Selected Solutions for Chapter 8: Sorting in Linear Time
Solution to Exercise 8.1-3
If the sort runs in linear time for m input permutations, then the height h of the portion of the decision tree consisting of the m corresponding leaves and their ancestor
Selected Solutions for Chapter 7: Quicksort
Solution to Exercise 7.2-3
PARTITION does a worst-case partitioning when the elements are in decreasing order. It reduces the size of the subarray under consideration by only 1 at each step, which weve seen has
Selected Solutions for Chapter 6: Heapsort
Solution to Exercise 6.1-1
Since a heap is an almost-complete binary tree (complete at all levels except possibly the lowest), it has at most 2hC1 1 elements (if it is complete) and at least 2h 1 C 1 D 2h element
Selected Solutions for Chapter 5: Probabilistic Analysis and Randomized Algorithms
Solution to Exercise 5.2-1
Since H IRE -A SSISTANT always hires candidate 1, it hires exactly once if and only if no candidates other than candidate 1 are hired. This event
Selected Solutions for Chapter 4: Divide-and-Conquer
Solution to Exercise 4.2-4
If you can multiply 3 3 matrices using k multiplications, then you can multiply n n matrices by recursively multiplying n=3 n=3 matrices, in time T .n/ D kT .n=3/ C .n2 /. Usi
Selected Solutions for Chapter 3: Growth of Functions
Solution to Exercise 3.1-2
To show that .n C a/b D .nb /, we want to nd constants c1 ; c2 ; n0 > 0 such that 0 c1 nb .n C a/b c2 nb for all n n0 . Note that n C a n C jaj 2n when jaj n , and n C a n ja