Randomized Algorithms
1
Randomized Algorithms
What to Randomize?
The world behaves randomly randomly generated
input solved by traditional algorithm
Average-case Analysis
The algorithm behaves randomly make random
decisions as the algorithm processes the

AVL Trees, Splay Trees,
and Amortized Analysis
1
AVL Trees, Splay Trees, and Amortized Analysis
AVL Trees
Target : Speed up searching (with insertion
and deletion)
root
Tool : Binary search
trees
small
large
Problem : Although Tp = O( height ), but the he

Inverted File Index
1
Inverted File Index
How can I find in which
retrieved web pages that include
"Computer Science"?
2
Inverted File Index
Solution 1: Scan each page for the string "Computer
Science".
How did Google do?
3
Inverted File Index
Solution

External Sorting
1
External Sorting
Why cant we simply do quicksort on a disk?
To get a[i] on
internal memory O(1)
hard disk
1. find the track;
device-dependent
2. find the sector;
3. find a[i] and transmit.
Tool : Merges
ort
To simplify
Store data on

Red-Black Trees
and B+ Trees
1
Red-Black Trees and B+ Trees
parent
color key
Red-Black Trees
Target : Balanced binary search
tree
left
right
NULL =
NIL
Definition A red-black tree is a binary search tree that
(1)
(2)
(3)
(4)
(5)
satisfies the following r

Leftist Heaps
and Skew Heaps
1
Leftist Heaps & Skew Heaps
Leftist Heaps
Target : Speed up merging in O(N).
Heap: Structure Property + Order Property
Discussion 5: How fast can we merge two heaps if
we simply use the original heap structure?
Leftist Heap:

Greedy Algorithms
1
Greedy Algorithms
Optimization Problems:
Given a set of constrains and an optimization function.
Solutions that satisfy the constrains are called feasible
solutions. A feasible solution for which the optimization
function has the best

Local Search
Local Search
Solve problems approximately
aims at a local optimum
Neighborhood
Gues
s
Global Minimum
Can the algorithm terminate
in a finite number of steps?
Until no improvement is possible
Local Search
Framework of Local Search
Local
Def

Dynamic Programming
1
Dynamic Programming
Solve sub-problems just once and save answers in a table
Use a table instead of recursion
1. Fibonacci Numbers: F(N) = F(N 1) + F(N 2)
int Fib( int N )
cfw_
if ( N <= 1 )
return 1;
else
return Fib( N - 1 ) + Fib(

Approximation
1
Approximation
What for?
Dealing with HARD problems
Getting around NP-completeness
If N is small, even O(2N) is acceptable
Solve some important special cases in polynomial ti
me
Find near-optimal solutions in polynomial time
approximat

NP Problems
1
NP Problems
NP-Completeness
Recall:
Euler circuit problem: Find a path that touches every edge
exactly once.
Hamilton cycle problem: Find a single cycle that contains
every vertex.
Single-source unweighted shortest-path problem
Single-s

Binomial Queue
1
Binomial Queues
Structure:
A binomial queue is not a heap-ordered tree, but rather a collection
of heap-ordered trees, known as a forest. Each heap-ordered tree is
According Constant!
toHavent
Theorem
a binomial tree.
we5.1 on p.156,
Wel

Backtracking
Backtracking
Rationale of the Backtracking Algorithms
A sure-fire way to find the answer to a problem is to make a
list of all candidate answers, examine each, and following the
examination of all or some of the candidates, declare the identi

Divide and Conquer
1
Divide and Conquer
Recursively:
Divide the problem into a number of sub-problems
Conquer the sub-problems by solving them recursively
Combine the solutions to the sub-problems into the sol
ution for the original problem
General recurr