CS383, Algorithms, Spring 2011, Midterm Exam
1. In insertion sort, we follow such a procedure: we rst nd the smallest element in array A
and exchange it with A, then we nd the second smallest element and exchange it with
A. We repeat the procedure (
CS383, Algorithms, Spring 2011, HW3 Solution
1. (2.4) (a) The recurrent relation is T (n) = 5T (n/2) + O(n). Using the master theorem, the
complexity of the algorithm is O(nlog2 ).
(b) The recurrent relation is T (n) = 2T (n 1) + O(n). We cannot use the
CS383, Algorithms, Spring 2011, HW2 Solution
1. (1.7) Without losing generality, lets assume x has length n, y has length m, and n > m.
Based on the multiplication algorithm, the computation terminates in m recursive calls. The
recursion tree is a single
CS383, Algorithms, Spring 2011, HW1 Solution
1. Most of the questions are straightforward. Some useful relations such as np = O(bn ), p >
0, b > 1 and logp (n) = O(nq ), p, q > 0 can be used to help the reasoning. (These two big O
relations are in fact th
CS383 Spring, 2011, HW4 Solutions
(3.9) With an adjacency list graph representation, we rst compute the degree of
each node (the number of edges incident on each node) by traversing each adjacency
list. The result can be stored in an array called onedegre
CS383 Spring, 2011, HW5 Solutions
(4.3) We can run a BFS for each node of the undirected graph. In each BFS, when updating
the neighbors dist values for node u, we also check whether dist(u) + dist(v ) = 3, where v is a
neighbor of u. If the condition sat
CS383 Algorithms, Spring 2011, Midterm Exam
March 24, 2011
Largest Number with an Upper Bound
Give an sorted sequence of numbers, nd the largest number that is not greater than an upper
bound. For instance, given an array cfw_1, 3, 8, 10, 15, 20, 35, th
CS383 HW7 Solutions
s.t. axi + byi c zi , i = 1.7
axi + byi c zi , i = 1.7
zi w, i = 1.7
zi 0, i = 1.7
min 3u + 5v
s.t. 2u + v 1
u + 3v 1
u, v 0
7.17 (e) Run the network ow algorithm and nd the nal residue network. For each edge in the orig
CS383, Algorithms, Spring 2011, HW6 Solution
6.1 We dene the subproblem S (i) to be the largest summation that terminates exactly at position
i. Let the input array be a[1.n].
The recurrence relation on S (i) is:
S (i) = maxcfw_S (i 1) + a[i], a[i].
CS393, Algorithms, Spring 2011, HW1
1. Exercise 0.1 in page 8 of the textbook.
2. Arrange the functions defined below in order of their asymptotic growth rates, from smallest
to largest. Include the sorted list, and explanations that justify your answer.