This le contains the exercises, hints, and solutions for Chapter 1 of the
book Introduction to the Design and Analysis of Algorithms, 2nd edition, by
A. Levitin. The problems that might be challenging for at least some students
are marked by ; those that

CP312 Assignment 3 Solutions 2004
Section 4.3, Question 3:
a) Every positive integer n is bounded below and above by some consecutive powers of 2, i.e. 2k n < 2k+1 , where k is a nonnegative integer
(uniquely dened by the value of n). Taking the base-2 lo

CP312 Assignment 1 Solutions 2004
Section 1.1, Question 9:
Outline: A straightforward algorithm that does not rely on the avail
ability of an approximate value of n can check the squares of consecutive
positive integers until the rst square exceeding n is

CP312 Fall 2007 Midterm
October 25, 2007
1:00-2:30
1. a) [1 mark] What is a cross edge?
An edge in a breadth rst search tree that connects a vertex to
an ancestor that is not its parent.
b) [1 mark] Finish this sentence: An algorithm is said to run in pla

1a) A Young tableau has distinct entries.
b) Because when we change the base we are just multiplying by a constant and constants are irrelevant in determining rate of growth. Change of
basis formula:
logc x
logb x =
logc b
c) Any three of: backtracking, b

CP312 Fall 2004 Midterm
October 22, 2004
2:304:00
1. a) [2 marks] Provide the formal, mathematical denition of what it means for a function f (n)
to be in O(g(n).
b)[1 mark] Is binary search a good example of a divideandconquer algorithm? Why or why
not?

CP312 Assignment 4 Solutions 2004
Section 5.2, Question 5:
Well prove the assertion in question by contradiction. Assume that a
BFS tree of some undirected graph has a cross edge connecting two vertices u
and v such that level[u] level[v]+2. But level[u]

CP312 Fall 2002 Midterm
October 25, 2002
2:304:00
1. a) [1 mark] What is the dierence between a Young tableau and a tableau?
b) [2 marks] Why is the base of a logarithm not important in algorithm analysis? Also give the
formula that explains why this is t

CP312 Fall 2007 Wdterm
November 23, 2007
Name:
ID Number:
Answer Question 1 on these pages. Answer Questions 2, 3, and 4 in the
exam booklet.
1. a) [1 mark] What is the principle behind best rst search? Le. how
does it decide which direction to go in a

assign1
http:/sauron.wlu.ca/physcomp/cp312/assign2.htm
Posted Oct 11, 2007
library search
Assignment 2
NOW DUE TUES, OCT 16 at 1pm
Assignment 2 is due Thurs, October 11 at 1pm. Assignments may be hand-written or typed, on one side of
the page, stapled in

assign1
http:/sauron.wlu.ca/physcomp/cp312/assign3.htm
Posted Oct 18, 2007
library search
Assignment 3
Assignment 3 is due Thurs, November 1 at 1pm. Assignments may be hand-written or typed, on one side of
the page, stapled in the upper left hand corner.

assign1
http:/sauron.wlu.ca/physcomp/cp312/assign4.htm
Posted Nov 06,
2007
library search
Assignment 4
Assignment 4 is due Thurs, November 15 at 1pm. Assignments may be hand-written or typed, on one side of
the page, stapled in the upper left hand corner.

CP312 Fall 2008 Midterm
October 23, 2008
1:00-2:20
1. a) [2 marks] Provide the formal, mathematical denition of what it
means for a function f(n) to be in @(g(n)).
b) [1 mark] What is the complexity of DFS if an adjacency matrix is
uSed to represent it?

CP312 Midterm Solutions
Fall 2001
1a) Amount of work done (complexity), Amount of space used, Simplicity/clarity (I accepted other
answers).
1b) o(g), O(g), (g) (I accepted other answers).
1c) Diagramatic representation of the recursive procedure. The lef

assign1
http:/sauron.wlu.ca/physcomp/cp312/assign1.htm
Posted Sep 20,
2007
library search
Assignment 1
Assignment 1 is due Thurs, September 27 at 1pm. Assignments may be hand-written or typed, on one side of
the page, stapled in the upper left hand corner

CP312 Midterm 2 2003
Solutions (Outline)
1. a) A directed graph with no directed cycles.
b) Sorting elements before running an algorithm. This is done if the
algorithm runs better on a sorted list.
c) Adjacency matrix and adjacency linked list. The deniti