






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







Review: Amortized Analysis
■ Both O(1) per Insert operation
n
j
j
n
i
lg
1 0
= =
Review: Accounting Analysis
■ Use $1 to perform immediate Insert()
■ Store $
■ $1 reinserts old item, $1 reinserts another old item
■ We’ve paid these costs up front with the last n /
Insert()s
Dynamic Programming
■ A metatechnique, not an algorithm
(like divide & conquer)
■ The word “programming” is historical and
predates computer programming
Dynamic Programming Example:
Longest Common Subsequence
■ Given two sequences x[1..m] and y[1..n], find the
longest subsequence which occurs in both
■ Ex: x = {A B C B D A B }, y = {B D C A B A}
■ {B C} and {A A} are both subsequences of both
○ What is the LCS?
■ Brute-force algorithm: For every subsequence of x,
check if it’s a subsequence of y
○ How many subsequences of x are there?
○ What will be the running time of the brute-force alg?
Finding LCS Length
■ What is the length of LCS of x and y?
max( [ , 1 ], [ 1 , ]) otherwise
[ 1 , 1 ] 1 if [ ] [ ], [ , ] c i j c i j
c i j x i y j c i j
The End