CS38, Spring 2012
Introduction to Algorithms
Prof. Alexei Kitaev
Solutions to problem set #3
Problem 1. Without loss of generality we may assume that h1 h2 . If h1 h2 2, we
can use the standard balancing procedure explained in class. So let us consider th
CS38
Midterm Exam
May 4, 2012
1. Due no later than Friday May 11, 2012 at 5:00pm in the computer lab.
2. This exam is not timed, plan your work as is convenient to you.
3. You may use the following resources during the exam: your own notes, homework probl
CS38, Spring 2012
Introduction to Algorithms
Prof. Alexei Kitaev
Solutions to problem set #6
Problem 1a. Here are the key steps:
2
2
2
3
11
3
6
3
11
6
7
11
6
7
4
7
1
9
1
1
1
2
4
2
2
3
9
3
3
11
6
11
6
7
7
11
6
7
Then we link a suitably labeled binomial tre
CS38, Spring 2012
Introduction to Algorithms
Prof. Alexei Kitaev
Solutions to problem set #7
Problem 1a. Let (V, s, c, d) be the original ow network, where c(x, y ) is the edge capacity
and d(x) is the vertex capacity. We dene an equivalent ordinary ow
CS38, Spring 2012
Introduction to Algorithms
Prof. Alexei Kitaev
Solutions to the midterm problems
Problem 1. We use a hash table with m = (n) slots and an AVL (or red-black) tree in each
slot.
Problem 2. We arrange a1 , . . . , an in the increasing order
CS38, Spring 2012
Introduction to Algorithms
Prof. Alexei Kitaev
Problem set #1
Due Friday April 13, 2012 at 5pm
in the box in the computer lab.
Problems
1. Exercises:
a) (4 points)
Sort the following functions in order of their asymptotic growth. (Use fo
CS38, Spring 2012
Introduction to Algorithms
Prof. Alexei Kitaev
Solutions to problem set #5
Problem 1a. For an arbitrary real number we can dene the edge weights to be w (u, v ) =
c(u, v ). Then the weighted length of a path p with k edges is equal to
w
CS38, Spring 2012
Introduction to Algorithms
Prof. Alexei Kitaev
Solutions to problem set #4
Problem 1. We sort activities according to nishing time in O (n log n). Let f1 , f2 , ., fn be
the sorted sequence. Let R[i + 1] be the maximum value of selecting
CS38, Spring 2012
Introduction to Algorithms
Prof. Alexei Kitaev
Problem set #2
Due Friday April 20, 2012 at 5pm
in the box in the computer lab.
Problems
1. See Problem 9-2 (weighted median) in the textbook. First, solve item a) for yourself to
make sure
CS38, Spring 2012
Introduction to Algorithms
Prof. Alexei Kitaev
Problem set #3
Due Friday April 27, 2012 at 5pm
in the box in the computer lab.
Problems
1. (10 points)
Let T be a binary search tree with height indicators located at each node. Denote by
T
CS38, Spring 2012
Introduction to Algorithms
Prof. Alexei Kitaev
Problem set #4
Due Friday May 4, 2012 at 5pm
in the box in the computer lab.
Problems
1. (10 points)
Consider a weighted version of the activity selection problem. There is a set of n propos
CS38, Spring 2012
Introduction to Algorithms
Prof. Alexei Kitaev
Problem set #5
Due Friday May 18, 2012 at 5 pm
in the box in the computer lab.
Problems
1. Part (a) of this problem is very similar to Problem 24-5 in CLRS.
Let G = (V, E ) be a directed gra
CS38, Spring 2012
Introduction to Algorithms
Prof. Alexei Kitaev
Problem set #6
Due Friday, May 25, 2012 at 5pm
in the box in the computer lab.
Problems
1. Fibonacci heaps.1
a) (5 points)
How can the following tree be built using two procedures: link (app
Problem set #7
Due Tuesday June 5, 2011 at 5pm
in the box in the computer lab.
CS38, Spring 2012
Introduction to Algorithms
Prof. Alexei Kitaev
Problems
1. Problem 26-1 in the textbook (escape problem).
a) (5 points)
b) (5 points)
2. It was shown in class
CS38, Spring 2012
Introduction to Algorithms
Prof. Alexei Kitaev
Solutions to problem set #1
Problem 1a. Let us transform some of the functions in question:
n log n = cn ln n (more precisely, n loga n = n ln n ). Using the sign for the bidirectional
ln a
CS38, Spring 2012
Introduction to Algorithms
Prof. Alexei Kitaev
Solutions to problem set #2
Problem 1b. We sort the pairs (xk , wk ) by xk . Then we scan the sequence, calculating the
sum of wk . We stop at the rst k for which k=1 wj 1/2.
j
Problem 1c. T