provinci summer training 2010 june 17: recursion and recursive decent parser june 24: greedy...
TRANSCRIPT
Provinci summer training 2010June 17: Recursion and recursive decent parser June 24: Greedy algorithms and stable marriage July 1: Holiday July 8: Math and number theory July 15: Coordinate geometry July 22: Black rain?July 29: Graph, MST, bipartite matching Aug 5: Black rain?Aug 12: Individual contest 1Aug 19: Individual contest 2 Aug 26: Dynamic programming Sep 2: RevisionSep 9: Team formation test
Recursion
1. Do something
2. Repeat
Any algorithm that have the above format is using "recursion".
Properties: Easy to design and write Tend to be slow (because trying all possibilities)
Greedy algorithms
1. Make a choice that looks good (greedy choice)
2. Repeat if the problem is not yet solved
Easy to design and write Tend to be fast (because make only 1 greedy
choice) Finding the correct greedy choice and proving
the correctness is usually hard.
Dynamic programming
The optimal solution
easier proble
m
easier proble
m
easier proble
m
easier proble
m
easier proble
m
easier proble
m
easier proble
m
Example 1. Magic bubbles
Given a sequence of n bubbles with colors Red, Green and Blue and a table of possible transformations. Determine whether we can form a bubble with targeted color.
Dynamic programming
Solution for [1,n]
[1,1] [1,2]
[2,3] [2,4]
[1,n]
[3,4]
[2,2]
Example 2. Cutting Sticks (UVA10003)
Dynamic programming
Solution for [1,n]
[1,1]
[2,3][1,2]
[2,2]
[3,4]
[4,4][3,3]
Optimal substructures
[1,3]
Overlapping subproblems
Example 3. Matrix multiplication
Example 4. Longest common subsequence
Example 5. Edit distance
Example 6. Prize collection
Example 7. Longest increasing subsequence
Example 8. Subset sum
Example 9. Optimal binary search tree
Example 10. Knapsack problem