CS38, Spring 2012
Introduction to Algorithms
Prof. Alexei Kitaev
Solutions to problem set #3
Problem 1. Without loss of generality we may assume that h1 h2 . If h1 h2 2, we
can use the standard balancing procedure explained in class. So let us consider th
CS38
Midterm Exam
May 4, 2012
1. Due no later than Friday May 11, 2012 at 5:00pm in the computer lab.
2. This exam is not timed, plan your work as is convenient to you.
3. You may use the following resources during the exam: your own notes, homework probl
#include <iostream>
#include <fstream>
using namespace std;
float GetInches(ifstream& rainFle, int numberOfDays);
/ Function returns the total inches of rain
/ Pre: File rainFile has been opened; numberOfDays is the
/
first value on the file, followed by
Capacitated graphs
Lecture 15 Max-Flow Min-Cut
These lecture notes for Introduction to Algorithms, CS38, are in draft
form. They may not be republished or posted without permission.
Leonard J. Schulman
Many logistics problems involve shipping something (c
Administrative
Lecture 11 Graph Components: Depth-First Search.
These lecture notes for Introduction to Algorithms, CS38, are in draft
form. They may not be republished or posted without permission.
Reading Chs. 22, 4, 7, 8, 9
Midterm out at the end of cl
Administrative
Lecture 17 Linear Programming: Further Examples;
Simplex Algorithm
Remember:
These lecture notes for Introduction to Algorithms, CS38, are in draft
form. They may not be republished or posted without permission.
Final exam next week. Format
Introduction to Clustering
One of the most important tasks in modern data analysis is clustering.
Lecture 8 Greedy Methods: Covering (Clustering) and
Packing
These lecture notes for Introduction to Algorithms, CS38, are in draft
form. They may not be repu
Administrative
Lecture 18 Simplex Algorithm, Strong LP Duality
These lecture notes for Introduction to Algorithms, CS38, are in draft
form. They may not be republished or posted without permission.
All instructions will be very similar to midterm; to be p
Administrative
Lecture 19 The Expressive Power of Linear
Programming
These lecture notes for Introduction to Algorithms, CS38, are in draft
form. They may not be republished or posted without permission.
Final exam out at end of class. Instructions on out
Linear Programming
Lecture 16 Linear Programming
These lecture notes for Introduction to Algorithms, CS38, are in draft
form. They may not be republished or posted without permission.
Leonard J. Schulman
Caltech
Goal: find a feasible point furthest along
Administrative
Lecture 5 Greedy Algorithms
These lecture notes for Introduction to Algorithms, CS38, are in draft
form. They may not be republished or posted without permission.
Remember recitations Tuesday 8:00pm
PS2-5 (solar panels NP-hardness) difficul
Linear prog. in poly-time: Khachiyans ellipsoid algorithm
Lecture 20 Ellipsoid Algorithm; Set Cover; Duality
Gaps and Dual Fitting
These lecture notes for Introduction to Algorithms, CS38, are in draft
form. They may not be republished or posted without p
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
cfw_
string str,st; / this string is to save the string
string origin[10]; / this string array is to save the source string from
textfile named "map2_ascii"
string re
Administrative
Lecture 7 Greedy Methods and Priority Queues
(Huffman Codes, Heapsort, Prims MST Alg)
These lecture notes for Introduction to Algorithms, CS38, are in draft
form. They may not be republished or posted without permission.
Reading: Chs. 24, 2
Lecture 3 cont. Dynamic Programming
These lecture notes for Introduction to Algorithms, CS38, are in draft
form. They may not be republished or posted without permission.
Note on ps1 problem 2, it is just as easy to get O(n2 ) as the requested
2 ). (But
Administrative
Lecture 6 Greedy Methods and Duality
These lecture notes for Introduction to Algorithms, CS38, are in draft
form. They may not be republished or posted without permission.
In problem 2-3 (-bonacci) you need compute P(n) only for integer n.
Administrative
Read the syllabus carefully.
Lecture 1 Course Overview. Recursion & Duality
These lecture notes for Introduction to Algorithms, CS38, are in draft
form. They may not be republished or posted without permission.
Normally, all homework submis
Administrative
Lecture 14 Divide and Conquer: Matrix Multiplication
and Inversion. Streaming Algorithms.
These lecture notes for Introduction to Algorithms, CS38, are in draft
form. They may not be republished or posted without permission.
Reading: Ch. 33
Administrative
Lecture 4 cont. Dynamic Programming
Reading CLRS Chs. 16, 21.1-3 (not covering path compression), 23
These lecture notes for Introduction to Algorithms, CS38, are in draft
form. They may not be republished or posted without permission.
PS1-
Divide & Conquer: Arithmetic
Arithmetic in decimal (or binary) notation. Addition is simple:
grade-school algorithm. Add two n-bit numbers in time O(n). Subtraction
equally easy.
Lecture 13 Divide and Conquer: Arithmetical and
Algebraic Computations (Inte
Administrative
Lecture 10 All-Pairs Shortest Paths (Floyd-Warshall,
Johnson); Space-Efficient s-t Connectivity (Savitch)
These lecture notes for Introduction to Algorithms, CS38, are in draft
form. They may not be republished or posted without permission.
Administrative
Lecture 9 Single-Source Shortest Paths (BFS, Dijkstra,
Bellman-Ford)
These lecture notes for Introduction to Algorithms, CS38, are in draft
form. They may not be republished or posted without permission.
Solution sets for the homework are a
Administrative
Lecture 12 Accelerating Exponential Search: Branch
and Bound. Divide and Conquer: Sorting and Selection
These lecture notes for Introduction to Algorithms, CS38, are in draft
form. They may not be republished or posted without permission.
R
CS38, Spring 2012
Introduction to Algorithms
Prof. Alexei Kitaev
Solutions to problem set #2
Problem 1b. We sort the pairs (xk , wk ) by xk . Then we scan the sequence, calculating the
sum of wk . We stop at the rst k for which k=1 wj 1/2.
j
Problem 1c. T
CS38, Spring 2012
Introduction to Algorithms
Prof. Alexei Kitaev
Solutions to problem set #1
Problem 1a. Let us transform some of the functions in question:
n log n = cn ln n (more precisely, n loga n = n ln n ). Using the sign for the bidirectional
ln a
Problem set #7
Due Tuesday June 5, 2011 at 5pm
in the box in the computer lab.
CS38, Spring 2012
Introduction to Algorithms
Prof. Alexei Kitaev
Problems
1. Problem 26-1 in the textbook (escape problem).
a) (5 points)
b) (5 points)
2. It was shown in class
CS38, Spring 2012
Introduction to Algorithms
Prof. Alexei Kitaev
Problem set #6
Due Friday, May 25, 2012 at 5pm
in the box in the computer lab.
Problems
1. Fibonacci heaps.1
a) (5 points)
How can the following tree be built using two procedures: link (app
CS38, Spring 2012
Introduction to Algorithms
Prof. Alexei Kitaev
Problem set #5
Due Friday May 18, 2012 at 5 pm
in the box in the computer lab.
Problems
1. Part (a) of this problem is very similar to Problem 24-5 in CLRS.
Let G = (V, E ) be a directed gra
CS38, Spring 2012
Introduction to Algorithms
Prof. Alexei Kitaev
Problem set #4
Due Friday May 4, 2012 at 5pm
in the box in the computer lab.
Problems
1. (10 points)
Consider a weighted version of the activity selection problem. There is a set of n propos
CS38, Spring 2012
Introduction to Algorithms
Prof. Alexei Kitaev
Problem set #3
Due Friday April 27, 2012 at 5pm
in the box in the computer lab.
Problems
1. (10 points)
Let T be a binary search tree with height indicators located at each node. Denote by
T