CS 124
Course Notes 1
Spring 2011
An algorithm is a recipe or a well-defined procedure for performing a calculation, or in general, for transforming
some input into a desired output. Perhaps the most familiar algorithms are those those for adding and mult
Lecture 14
14-6
Multiplying both sides by 11 , 21 , . . . , (p 1)1 we have
1 = a p1 mod p.
This proves Claim 5.
We now return to the end of Claim 4, where we must prove
x1+k(p1)(q1) = x mod n.
We first claim that x1+k(p1)(q1) = x mod p. This is clearly tr
CS124
Lecture 9
Spring 2010
9.1 The String reconstruction problem
The greedy approach doesnt always work, as we have seen. It lacks flexibility; if at some point, it makes a wrong
choice, it becomes stuck.
For example, consider the problem of string recon
Lecture 13
CS124
Hopefully the ideas we saw in our hashing problems have convinced you that randomness is a useful tool in
the design and analysis of algorithms. Just to make sure, we will consider several more example of how to use
randomness to design a
CS124
15.1
Lecture 15
2SAT
We begin by showing yet another possible way to solve the 2SAT problem. Recall that the input to 2SAT is a logical
expression that is the conjunction (AND) of a set of clauses, where each clause is the disjunction (OR) of two li
Lecture 16
16-10
max-flow problem as well that improve on this running time.
To summarize: the max-flow problem can be easily reduced to linear programming and solved by simplex. But
it is easier to understand what simplex would do by following its iterat
CS124
Lecture 17
Network Flows
Suppose that we are given the network in top of Figure 17.1, where the numbers indicate capacities, that is, the
amount of flow that can go through the edge in unit time. We wish to find the maximum amount of flow that can g
CS124
Lecture 19
We have defined the class of NP-complete problems, which have the property that if there is a polynomial time
algorithm for any one of these problems, there is a polynomial time algorithm for all of them. Unfortunately, nobody
has found a
CS124
NP-Completeness Review
Where We Are Headed
Up to this point, we have generally assumed that if we were given a problem, we could find a way to solve
it. Unfortunately, as most of you know, there are many fundamental problems for which we have no eff
Lecture 20
CS124
Heuristics can be useful in practice, but sometimes we would like to have guarantees. Approximation algorithms
give guarantees. It is worth keeping in mind that sometimes approximation algorithms do not always perform as well
as heuristic
CS 124
Lecture 21
We now consider a natural problem that arises in many applications, particularly in conjunction with suffix
trees, which we will study later. Suppose we have a rooted tree T with n nodes. We would like to be able to answer
questions of t
Lecture 12
CS124
12.1 Near duplicate documents1
Suppose we are designing a major search engine. We would like to avoid answering user queries with multiple
copies of the same page. That is, there may be several pages with exactly the same text. These dupl
Lecture 11
CS 124
11.1 Applications: Fingerprinting for pattern matching
Suppose we are trying to find a pattern string P in a long document D. How can we do it quickly and efficiently?
Hash the pattern P into say a 16 bit value. Now, run through the file
Lecture 2
CS 124
In order to discuss algorithms effectively, we need to start with a basic set of tools. Here, we explain these tools
and provide a few examples. Rather than spend time honing our use of these tools, we will learn how to use them by
applyi
CS124
Lecture 4
Spring 2011
Breadth-First Search
A searching technique with different properties than DFS is Breadth-First Search (BFS). While DFS used an
implicit stack, BFS uses an explicit queue structure in determining the order in which vertices are
CS124
Lecture 3
Spring 2011
Graphs and modeling
Formulating a simple, precise specification of a computational problem is often a prerequisite to writing a
computer program for solving the problem. Many computational problems are best stated in terms of g
Unbiasing Random Bits
Michael Mitzenmacher
1. Introduction
Most computers use a pseudo-random number generator in order to mimic
random numbers. While such pseudo-random numbers are sufficient for
many applications, they may not do in cases where more sec
Tossing a Biased Coin
Michael Mitzenmacher
When we talk about a coin toss, we think of it as unbiased: with probability one-half it comes up heads,
and with probability one-half it comes up tails. An ideal unbiased coin might not correctly model a real
co
CS124
Lecture 6
Spring 2011
Disjoint set (Union-Find)
For Kruskals algorithm for the minimum spanning tree problem, we found that we needed a data structure for
maintaining a collection of disjoint sets. That is, we need a data structure that can handle t
CS124
Lecture 5
Spring 2011
Minimum Spanning Trees
A tree is an undirected graph which is connected and acyclic. It is easy to show that if graph G(V, E) that
satisfies any two of the following properties also satisfies the third, and is therefore a tree:
Lecture 7
CS124
In todays lecture we will be looking a bit more closely at the Greedy approach to designing algorithms. As we
will see, sometimes it works, and sometimes even when it doesnt, it can provide a useful result.
Horn Formulae
A simple applicati
Lecture 10
CS124
Spring 2011
10.1 The Birthday Paradox
How many people do there need to be in a room before with probability greater than 1/2 some two of them have the
same birthday? (Assume birthdays are distributed uniformly at random.)
Surprisingly, on
CS124
Lecture 8
Spring 2011
Divide and Conquer
We have seen one general paradigm for finding algorithms: the greedy approach. We now consider another
general paradigm, known as divide and conquer.
We have already seen an example of divide and conquer algo
CS 124
Lecture 22
Spring 2011
Suffix trees are an old data structure that have become new again, thanks to a recent new linear time algorithm
for constructing suffix trees due to Ukkonen that proves more useful for many applications. Here, we will describ