provinci summer training 2010 june 17: recursion and recursive decent parser june 24: greedy...

16
Provinci summer training 2010 June 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 1 Aug 19: Individual contest 2 Aug 26: Dynamic programming Sep 2: Revision Sep 9: Team formation test

Upload: shannon-paul

Post on 13-Dec-2015

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Provinci summer training 2010 June 17: Recursion and recursive decent parser June 24: Greedy algorithms and stable marriage July 1: Holiday July 8: Math

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

Page 2: Provinci summer training 2010 June 17: Recursion and recursive decent parser June 24: Greedy algorithms and stable marriage July 1: Holiday July 8: Math

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)

Page 3: Provinci summer training 2010 June 17: Recursion and recursive decent parser June 24: Greedy algorithms and stable marriage July 1: Holiday July 8: Math

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.

Page 4: Provinci summer training 2010 June 17: Recursion and recursive decent parser June 24: Greedy algorithms and stable marriage July 1: Holiday July 8: Math

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

Page 5: Provinci summer training 2010 June 17: Recursion and recursive decent parser June 24: Greedy algorithms and stable marriage July 1: Holiday July 8: Math

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.

Page 6: Provinci summer training 2010 June 17: Recursion and recursive decent parser June 24: Greedy algorithms and stable marriage July 1: Holiday July 8: Math

Dynamic programming

Solution for [1,n]

[1,1] [1,2]

[2,3] [2,4]

[1,n]

[3,4]

[2,2]

Page 7: Provinci summer training 2010 June 17: Recursion and recursive decent parser June 24: Greedy algorithms and stable marriage July 1: Holiday July 8: Math

Example 2. Cutting Sticks (UVA10003)

Page 8: Provinci summer training 2010 June 17: Recursion and recursive decent parser June 24: Greedy algorithms and stable marriage July 1: Holiday July 8: Math

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

Page 9: Provinci summer training 2010 June 17: Recursion and recursive decent parser June 24: Greedy algorithms and stable marriage July 1: Holiday July 8: Math

Example 3. Matrix multiplication

Page 10: Provinci summer training 2010 June 17: Recursion and recursive decent parser June 24: Greedy algorithms and stable marriage July 1: Holiday July 8: Math

Example 4. Longest common subsequence

Page 11: Provinci summer training 2010 June 17: Recursion and recursive decent parser June 24: Greedy algorithms and stable marriage July 1: Holiday July 8: Math

Example 5. Edit distance

Page 12: Provinci summer training 2010 June 17: Recursion and recursive decent parser June 24: Greedy algorithms and stable marriage July 1: Holiday July 8: Math

Example 6. Prize collection

Page 13: Provinci summer training 2010 June 17: Recursion and recursive decent parser June 24: Greedy algorithms and stable marriage July 1: Holiday July 8: Math

Example 7. Longest increasing subsequence

Page 14: Provinci summer training 2010 June 17: Recursion and recursive decent parser June 24: Greedy algorithms and stable marriage July 1: Holiday July 8: Math

Example 8. Subset sum

Page 15: Provinci summer training 2010 June 17: Recursion and recursive decent parser June 24: Greedy algorithms and stable marriage July 1: Holiday July 8: Math

Example 9. Optimal binary search tree

Page 16: Provinci summer training 2010 June 17: Recursion and recursive decent parser June 24: Greedy algorithms and stable marriage July 1: Holiday July 8: Math

Example 10. Knapsack problem