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

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.

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: 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 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

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

CSOR 4231, Fall 2015
Problem Set 4 Solutions
Problem 1. Exercise 16.2-7. Maximizing a payo.
Sort A and B into monotonically increasing order.
Heres a proof that this method yields an optimal solution. Consider any indices i and j such
that i < j, and cons

CSOR 4231, Fall 2015
Problem Set 2 Solutions
Problem 1
Maintain a min-heap that always contains exactly k elements, one from each list. The lists are
all merged together at once by repeatedly extracting the minimum element from the heap and
outputting it.

Analysis of Algorithms, I
CSOR S4231
Eleni Drinea
Computer Science Department
Columbia University
Lecture 8: cache maintenance
Outline
1 Recap
2 Cache maintenance (the offline problem)
3 A greedy optimal algorithm for the offline problem:
Farthest-into-Fu

Midterm Exam Guidelines
The midterm exam will be held on Tuesday October 27, at 11:40-12:55, in the usual classroom
501 Northwest Corner. Make sure you arrive early and are seated by 11:35 so that we can
distribute the exam in an orderly fashion.
The exam

CSOR 4231, Fall 2015
Problem Set 3 Solutions
Problem 1. Problem 9-4. Randomized Selection Analysis
1. As in the quicksort analysis, elements zi and zj will not be compared with each other if any
element in cfw_zi+1 , zi+2 , . . . , zj1 is chosen as a piv

Quicksort
Quicksort(A, p, r)
1
2
3
4
if p < r
then q Partition(A, p, r)
Quicksort(A, p, q 1)
Quicksort(A, q + 1, r)
Partition(A, p, r)
1
2
3
4
5
6
7
8
9
10
y random(p, r)
Exchange A[y] and A[r]
x A[r]
ip1
for j p to r 1
do if A[j] x
then i i + 1
exchange

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

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

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

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

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

CS4231: Analysis of Algorithms, I
Midterm Exam Solutions, Tuesday October 21, 2014
Problem 1 [18 points, 6 points per part]
Give asymptotic solutions T(n) = (g(n) for the following recurrences. Assume that T(n)
is constant for sufficiently small n. State

Greedy Algorithms
CS 4231, Fall 2015
Mihalis Yannakakis
1
Optimization Problems
For given instance of the problem, there is a set
of feasible solutions, involving a number of
choices (or decisions)
Every solution has a cost or a value: metric for
evalua

Depth First Search
Acyclicity
Graph Components
CS 4231, Fall 2015
Mihalis Yannakakis
1
Depth-First Search from a source s
R
s
N-R
u
v
Policy: Choose edge (u,v) from R (reached nodes) to N-R
(unreached) where u is latest node added to reachable
set R
Can

Analysis of Algorithms, I
CSOR S4231
Eleni Drinea
Computer Science Department
Columbia University
Lecture 7: Huffman coding
Outline
1 Recap
2 Data compression
3 Symbol codes and optimal lossless compression
4 Prefix codes
5 Prefix codes and trees
6 The Hu

2/11/2016
Analysis of Algorithms I,
CSOR W4231
Spring 2016, Lecture 7
Allison Bishop
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
2/11/2016
Compariso

2/22/2016
Analysis of Algorithms I,
CSOR W4231
Spring 2016, Lecture 10
Allison Bishop
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,

2/15/2016
Analysis of Algorithms I,
CSOR W4231
Spring 2016, Lecture 8
Allison Bishop
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

2/18/2016
Dictionary
Set / Search/ Index structure
Analysis of Algorithms I,
CSOR W4231
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

2/2/2016
Analysis of Algorithms I,
CSOR W4231
Spring 2016, Lecture 6
Allison Bishop
TexPoint fonts used in EMF.
Read the TexPoint manual before you delete this box.: AAAAAAA
Selection (Order Statistics)
Input: Set A of n numbers, number i, 1in
Output: i

2/1/2016
Analysis of Algorithms I,
CSOR W4231
Spring 2016, Lecture 5
Allison Bishop
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

1/27/2016
Analysis of Algorithms I,
CSOR W4231
Spring 2016, Lecture 4
Allison Bishop
TexPoint fonts used in EMF.
Read the TexPoint manual before you delete this box.: AAAAAAA
The Closest Pair Problem
Problem:
Given n points in the plane in arbitrary order

COMS 4231: Analysis of Algorithms I, Fall 2016
Problem Set 1, due Thursday September 22, 11:40am on Courseworks
Please follow the homework submission guidelines posted on
courseworks
Problem 1. For each of the following two code fragments, give its asympt

Examples of
Divide and Conquer
and the Master theorem
CS 4231, Fall 2016
Mihalis Yannakakis
Divide and Conquer
Reduce to any number of smaller instances:
1. Divide the given problem instance into
subproblems
2. Conquer the subproblems by solving them
recu