CS4231: Analysis of Algorithms, I
Midterm Exam, Tuesday October 21, 2014
This exam ends at 12:55 PM. It contains 5 problems, some of them composed of several
parts. There are 100 points in all, and you have 75 minutes. Do not spend too much time
on any pr

SOLUTIONS: HOMEWORK 3
Problem 1
Samuel Frank
a. Note that once we select which numbers will be in the rst list,
we are forced to use the rest of the numbers in the second list.
So, this question is equivalent to asking how many ways we can
choose n number

CSOR 4231, Fall 2015
Problem Set 1 Solutions
Problem 1 (Graded by Drishan Arora)
1 First we show that (an + b)d = O(nd ). To do so, we just need to pick appropriate positive
constants n0 and c. We set c = (2a)d , and n0 = b/a. Note that for n n0 , n b/a.

SOLUTIONS: PROBLEMS 1 AND 2
SAMUEL FRANK
1:
(a) f (n) = o (g(n) and f (n) = O (g(n). f is a degree 3 polynomial
and g is a degree 4 polynomial. A smaller degree polynomial
is always little-o of a larger degree polynomial. f (n) = o(g(n)
immediately implie

SOLUTIONS: HOMEWORK 5
Problem 1
a. If a graph contains a cycle of odd length, lets say the nodes along
the cycle are a1 , a2 , . . . , an .
If the graph is bipartite, that would mean:
a1 and a2 are in dierent subsets. Without loss of generality, lets
assu

Analysis of Algorithms - HW2 Solutions
October 6, 2014
Problem 1 (WY)
The rst 3 problems have 5 points, and problem (d) (e) (f) each worth 5 points.
(a) T (n) = 4T (n/2) + n2
According to the master theorem, a = 4, b = 2, f (n) = n2 , thus we have
n
= nlo

11/6/2014
Analysis of Algorithms I,
CSOR W4231
Fall 2014, Lecture 18
Allison Lewko
TexPoint fonts used in EMF.
Read the TexPoint manual before you delete this box.: AAAAAAA
Review: Single-source shortest paths general weights:
Bellman-Ford Algorithm
Inpu

11/19/2014
Analysis of Algorithms I,
CSOR W4231
Fall 2014, Lecture 22
Allison Lewko
TexPoint fonts used in EMF.
Read the TexPoint manual before you delete this box.: AAAAAAA
Review: The Class NP
The name NP stands for Nondeterministic Polynomial time:
a

11/24/2014
Analysis of Algorithms I,
CSOR W4231
Fall 2014, Lecture 23
Allison Lewko
TexPoint fonts used in EMF.
Read the TexPoint manual before you delete this box.: AAAAAAA
Review: NP-hardness and NP-completeness
A language L (decision problem) is NP-har

Analysis of Algorithms - HW4 Solutions
November 11, 2014
Problem 1 (JH)
We can simply do a greedy algorithm like this: First of all sort all the set of
points with any O(n log n) sorting algorithm such that x1 x2 xn .
Then we can insert an interval coveri

9/4/2014
Analysis of Algorithms I,
CSOR W4231
Fall 2014, Lecture 2
Allison Lewko
TexPoint fonts used in EMF.
Read the TexPoint manual before you delete this box.: AAAAA
More Examples of Asymptotic Notations:
Which grows faster as n ! 1?
p
n + log(n)
or
5n

9/22/2014
Analysis of Algorithms I,
CSOR W4231
Fall 2014, Lecture 7
Allison Lewko
TexPoint fonts used in EMF.
Read the TexPoint manual before you delete this box.: AAAAAAA
And now something we have so far
neglected Lower Bounds!
2
1
9/22/2014
Comparison S

11/18/2014
Analysis of Algorithms I,
CSOR W4231
Fall 2014, Lecture 21
Allison Lewko
TexPoint fonts used in EMF.
Read the TexPoint manual before you delete this box.: AAAAAAA
Towards Understanding the
Hardness of a Problem
Motivating Idea: we want to rough

11/13/2014
Analysis of Algorithms I,
CSOR W4231
Fall 2014, Lecture 20
Allison Lewko
TexPoint fonts used in EMF.
Read the TexPoint manual before you delete this box.: AAAAAAA
Linear Programming
We previously saw the Max Flow problem was a particular
examp

11/10/2014
Analysis of Algorithms I,
CSOR W4231
Fall 2014, Lecture 19
Allison Lewko
TexPoint fonts used in EMF.
Read the TexPoint manual before you delete this box.: AAAAAAA
Review: Flow Network
Directed Graph G=(N,E)
Positive capacities on edges c: E R

9/24/2014
Analysis of Algorithms I,
CSOR W4231
Fall 2014, Lecture 8
Allison Lewko
TexPoint fonts used in EMF.
Read the TexPoint manual before you delete this box.: AAAAAAA
Quick Review: Radix Sorting
Input elements: d-digit numbers, each digit takes k po

10/1/2014
Analysis of Algorithms I,
CSOR W4231
Fall 2014, Lecture 10
Allison Lewko
TexPoint fonts used in EMF.
Read the TexPoint manual before you delete this box.: AAAAAAA
Balanced Trees
BST trees after random insertions have O(logn)
expected height, bu

9/30/2014
Analysis of Algorithms I,
CSOR W4231
Fall 2014, Lecture 9
Allison Lewko
TexPoint fonts used in EMF.
Read the TexPoint manual before you delete this box.: AAAAAAA
Dictionary
Set / Search/ Index structure
Maintain set S of items, each item has key

10/6/2014
Analysis of Algorithms I,
CSOR W4231
Fall 2014, Lecture 11
Allison Lewko
TexPoint fonts used in EMF.
Read the TexPoint manual before you delete this box.: AAAAAAA
Augmenting Data Structures
Can add auxiliary information to facilitate other quer

10/8/2014
Analysis of Algorithms I,
CSOR W4231
Fall 2014, Lecture 12
Allison Lewko
TexPoint fonts used in EMF.
Read the TexPoint manual before you delete this box.: AAAAAAA
Greedy Algorithms
1
10/8/2014
Optimization Problems
For given instance of the pro

10/15/2014
Analysis of Algorithms I,
CSOR W4231
Fall 2014, Lecture 14
Allison Lewko
TexPoint fonts used in EMF.
Read the TexPoint manual before you delete this box.: AAAAAAA
Recall - Graphs
Graph G=(V,E)
set V of vertices or nodes represents collection

10/13/2014
Analysis of Algorithms I,
CSOR W4231
Fall 2014, Lecture 13
Allison Lewko
TexPoint fonts used in EMF.
Read the TexPoint manual before you delete this box.: AAAAAAA
Dynamic Programming
General method that applies to a class of
problems, often a c

10/27/2014
Analysis of Algorithms I,
CSOR W4231
Fall 2014, Lecture 16
Allison Lewko
TexPoint fonts used in EMF.
Read the TexPoint manual before you delete this box.: AAAAAAA
Strongly Connected Directed Graph
mutually reachable relation: u - - v and v - -

10/23/2014
Analysis of Algorithms I,
CSOR W4231
Fall 2014, Lecture 15
Allison Lewko
TexPoint fonts used in EMF.
Read the TexPoint manual before you delete this box.: AAAAAAA
Connected Components of an Undirected Graph
Connected(u,v) =
path connecting u,v

10/30/2014
Analysis of Algorithms I,
CSOR W4231
Fall 2014, Lecture 17
Allison Lewko
TexPoint fonts used in EMF.
Read the TexPoint manual before you delete this box.: AAAAAAA
Shortest Paths
Given graph (directed or undirected) G=(N,E) with lengths (or
wei

9/16/2014
Analysis of Algorithms I,
CSOR W4231
Fall 2014, Lecture 5
Allison Lewko
TexPoint fonts used in EMF.
Read the TexPoint manual before you delete this box.: AAAAAAA
Quick Review: Random Variables, Expectation
Random variable X: Maps Sample space S

Randomization in Algorithms
Randomization is a tool for designing good algorithms.
Two kinds of algorithms
Las Vegas - always correct, running time is random.
Monte Carlo - may return incorrect answers, but running time is
deterministic.
Hiring Proble

Randomized Selection
Same start as for deterministic selection
Select(A,i,n)
1
2
if (n = 1)
then return A[1]
3
4
5
p = median(A)
6
L = cfw_x A : x p
H = cfw_x A : x > p
7
8
9
if i |L|
then Select(L, i, |L|)
else Select(H, i |L|, |H|)
Choose pivot p random

Search Trees
CS 4231, Fall 2015
Mihalis Yannakakis
1
Dictionary
Search/ Index structure
Maintain set S of items, each item has key and other info
Basic Operations:
Insert an item x
Search for an item with given key k
Other operations: empty?, size, list a

1. Exercise 23.1-3 and 23.1-8 on Page 629.
2. Problem 23-4 on Page 641: Alternative minimum-spanning-tree algorithms. For each of the
three algorithms, either give a counterexample or prove that it always outputs a minimum
spanning tree. Make sure your pr