CS 584 Algorithms: Design and Analysis
Fall term 2013
Solutions for the Midterm Exam
1. Assume that the function T satises the following recurrence relation
T (n) = 2T ( n) + log n,
whenever n is a perfect square greater than 1 and T (2) = 1.
(a) Find T (
CS 584 Algorithms; Design and Analysis
Fall term 2013
Homework 1, due Wednesday, September 18
Most homeworks will be worth 100 points; consider the point value in
determining how much time you spend on each question. The exercise and
page numbers are from
CS 584 Algorithms: Design and Analysis
Fall term 2013
Homework 2, due Wednesday, October 2
READING: Chapters 6-9.
1. In our MERGE-SORT algorithm we merged two sorted lists into one
sorted list in O(n) time. Describe an O(n log k )-time algorithm to
merge
CS 584 Algorithms: Design and Analysis
Fall term 2013
Solutions for Homework 1
1. Find the least integer k such that f (n) is O(nk ) for each of the following
functions:
(a) f (n) = 2n2 + n3 log n
(b) f (n) = 3n5 + (log n)4
(c) f (n) = (n4 + n2 + 1)/(n4 +
CS 584 Algorithms: Design and Analysis
Fall term 2013
Solutions for Homework 5
1. Describe an algorithm for nding a spanning tree with minimal weight
containing a specied acyclic (cycle-free) set of edges A in a connected
weighted undirected graph.
Soluti
CS 584 Algorithms: Design and Analysis
Fall term 2013
Solutions for Homework 3
1. Exercise 12.2-5 on page 293.
Solution: Let x be a node with two children. Since x has a right child
the successor s of x is in the right subtree of x. Then s cannot have
a l
CS 584 Algorithms: Design and Analysis
Fall term 2013
Solutions for Homework 4
1. Suppose we perform a sequence of n operations on a data structure
in which the i-th operation costs i if i is an exact power of 2, and 1
otherwise. Use the accounting method
CS 584 Algorithms: Design and Analysis
Fall term 2013
Solutions for Homework 2
1. In our MERGE-SORT algorithm we merged two sorted lists into one
sorted list in O(n) time. Describe an O(n log k )-time algorithm to
merge k sorted lists into one sorted list
CS 584 Algorithms: Design and Analysis
Fall term 2013
Solutions for Homework 6
1. Suppose you seek a ow f in a multiple source, multiple sink network
G = (V, E ), where V = cfw_s1 , . . . , sm , t1 , . . . , tn , v1 , . . . , vp with sources
s1 , . . . ,
CS 584 Algorithms: Design and Analysis
Fall term 2013
Homework 3, due Wednesday, October 30
READING: Chapters 10-12, 15-17.
1. Exercise 12.2-5 on page 293. (15 points)
2. In an experiment you pick at random a bit string of length 5. Consider
the following
CS 584 Algorithms: Design and Analysis
Fall term 2013
Solutions for the Practice Final Exam
These problems are sample problems for the nal exam, so you may expect
similar problems in the nal. Do not hand in your solutions. Solutions will
be handed out, di
CS 584 Algorithms: Design and Analysis
Fall term 2013
Practice Final Exam
These problems are sample problems for the nal exam, so you may expect
similar problems in the nal. Do not hand in your solutions. Solutions will
be handed out and discussed in clas
CS 584 Algorithms: Design and Analysis
Fall term 2013
Homework 4, due Wednesday, November 13
READING: Chapters 17, 19.
1. Suppose we perform a sequence of n operations on a data structure
in which the i-th operation costs i if i is an exact power of 2, an
CS 584 Algorithms: Design and Analysis
Fall term 2013
Homework 6, due Wednesday, December 11
READING: Chapters 26, 34, 35.
1. Suppose you seek a ow f in a multiple source, multiple sink network
G = (V, E ), where V = cfw_s1 , . . . , sm , t1 , . . . , tn
CS 584 Algorithms: Design and Analysis
Fall term 2013
Homework 5, due Wednesday, December 4
READING: Chapters 22-25.
1. Describe an algorithm for nding a spanning tree with minimal weight
containing a specied acyclic (cycle-free) set of edges A in a conne
CS5084: Algorithms Fall 2011
Solution for Test 8 October 24, 2012
Posted: 00:19, October 25, 2012
1. The first problem in the homework concerned an optimal algorithm to find the two largest
items in a set of n numbers. It used a knock-out tournament.
Howe
CS5084: Algorithms Fall 2012
Solution for Test 5 September 26, 2012
Posted: 16:02, September 27, 2012
1. (a) How many inversions are there in the array h 4 12 6 2 7 1 15 8 10 i.
Solution:
(a) Fourteen inversions: (4,2), (4,1); (12,6), (12, 2) (12, 7) (12,
CS5084: Algorithms Fall 2012
Solution for Test 3 September 12, 2012
Date posted: September 12, 2012
1. (a) What is a necessary and sufficient condition for nx = nx when n is integer, and x
real, both positive?
(b) Let n be an integer, and x a positive num
CS5084: Introduction to Algorithms Fall 2012
Solution for Test 6 October 3, 2012
Posted: 21:29, October 3, 2012
1. MergeSort and inversions
(a) Explain how you would adapt the operation of the standard binary MergeSort in order to
count the number of inve
CS5084: Algorithms Fall 2013
Homework 6
1. Exercise 7.1-4, page 174: How would you modify QS to sort into nonincreasing order?
2. Exercise 7.3-1, page 180: "Why do we analyze the expected running time of a randomized algorithm, and not its worst-case runn
CS5084: Algorithms Fall 2013
Homework 10
1. One more BFS-based algorithm; it takes some imagination. Exercise 22.2-8, page 602.
The diameter of a tree T = (V, E) is defined as the largest (in number of hops) among all shortestpaths between any two nodes i
CS5084: Algorithms Fall 2013
Solution for Homework 1;
Time posted: September 8, 2013, 17:17
Note: The occasional starred () exercise is for the ambitious, and will not be used in the test.
k1
= 0. It is simple if you use a result shown in class.
k
k>0 2
S
CS5084: Algorithms Fall 2013
Homework 5
1. We have seen inversions in a list (or array); we say a pair of entries which are in descending order
in the list (ai and a j , where i < j and ai > a j ) is an inversion.
Your task: describe a comparison-based al
CS5084: Introduction Algorithms Fall 2012
Solution for Homework 7
Posted: 21:32, October 28, 2013
1. One more problem related to selection.
Adapted from problem 9.1 of the text, page 224.
Given an array with n distinct numbers, you need to find the m larg
CS5084: Algorithms Fall 2013
Homework 3
1. You are given a 1-origin array W of size n which contains distinct integers. The array was sorted,
and then rotated circularly, clockwise, (read: shifted left, circularly) by k > 0 positions.
(a) You know k: in w
CS5084: Algorithms Fall 2013
Homework 1
Note: The occasional starred () exercise is for the ambitious, and will not be used in the test.
1. Show that
k1
= 0. It is simple if you use a result shown in class.
k
k>0 2
n
2. Evaluate the product
k=1
2 4k .
Hin
CS5084: Algorithms Fall 2013
Homework 9
The first two problems are still about dynamic programming, and they are both quite involved.
1. TSP the Traveling Salesman Problem is formulated as follows: Given a weighted undirected
graph, G = (V, E; D), represe
CS5084: Algorithms Fall 2013
Solution for Homework 2;
Time posted: September 16, 2013, 23:22
1. This is about using the integer functions, floor and ceiling, that you saw in analyzing binary search.
One more notation I did not get to use in class: for any
CS5084: Algorithms Fall 2013
Solution for Homework 4
Posted: 22:25, September 29, 2013
1. Exercise 5.2-4, page 122.
One version of the hat-check problem: A restaurant gets each of its n customers to leave his/her hat
at the courtesy counter. As they leave
CS5084: Algorithms Fall 2012
Solution for Test 11 November 14, 2012
Posted: 12:36, November 16, 2012
1. (a) The following undirected 5-node graph was shown in the last homework, and a specific claim
was made about it. What was the claim? And how would you
CS5084: Algorithms Fall 2012
Solution for Test 4 September,19, 2012
Date posted: September 20, 2012
1. (a) How would you adapt the binary search algorithm as seen in class to work correctly with
an array sorted in decreasing order?
Solution:
(a) Nearly id
CS5084: Algorithms Fall 2012
Solution for Test 9 October 31, 2012
Posted: 12:43, November 2, 2012
1. Suppose we have inserted the natural numbers 1. . . 1000 properly into a binary search tree, in
some (unknown) order, and now we search for the number 500
CS5084: Introduction to Algorithms Fall 2012
Solution for Test 7 October 10, 2012
Posted: 01:32, October 11, 2012
1. How would you modify QS to sort into nonincreasing order?
Solution: There is no need to touch the function QS.
In the partition function y
CS5084: Algorithms Fall 2012
Solution for Test 2 September 5, 2012
Date posted: September 6, 2012
Name:
ni=0 37i
1. (a) Is the following a geometric series? Explain:
(b) Evaluate the expression in part (a).
Solution: (a) No. It is not a seriesa series alw
CS5084: Algorithms Fall 2012
Solution for Test 10 November 7, 2012
Posted: 22:15, November 7, 2012
1. In the question about finding good and / or optimal structures for a binary search tree you
were given formulas for the underlying probability distributi