Steven Skiena. skiena

Similar documents
Lecture 6: Combinatorics Steven Skiena. skiena

Lecture 24: More Reductions (1997) Steven Skiena. skiena

Lecture 4: Dynamic programming I

CSE 417 Dynamic Programming (pt 4) Sub-problems on Trees

Lecture 16: Introduction to Dynamic Programming Steven Skiena. Department of Computer Science State University of New York Stony Brook, NY

Steven Skiena. skiena

Algorithms IV. Dynamic Programming. Guoqiang Li. School of Software, Shanghai Jiao Tong University

Lecture 21: Other Reductions Steven Skiena. Department of Computer Science State University of New York Stony Brook, NY

Optimization II: Dynamic Programming

Unit 4: Dynamic Programming

Polygon Triangulation

Computational Geometry [csci 3250]

The Algorithm Design Manual

Dynamic Programming Homework Problems

Lecture 3. Brute Force

Dynamic Programming II

Lecture 13: Divide and Conquer (1997) Steven Skiena. skiena

Lecture 21: Other Reductions Steven Skiena

6. Algorithm Design Techniques

Computational Geometry

Dynamic Programming Homework Problems

Design and Analysis of Algorithms 演算法設計與分析. Lecture 7 April 15, 2015 洪國寶

CSE 101, Winter Design and Analysis of Algorithms. Lecture 11: Dynamic Programming, Part 2

CS473-Algorithms I. Lecture 10. Dynamic Programming. Cevdet Aykanat - Bilkent University Computer Engineering Department

Computational Discrete Mathematics

Dynamic Programming Algorithms

So far... Finished looking at lower bounds and linear sorts.

S. Dasgupta, C.H. Papadimitriou, and U.V. Vazirani 165

F(0)=0 F(1)=1 F(n)=F(n-1)+F(n-2)

Unit-5 Dynamic Programming 2016

CSE 4/531 Solution 3

Computational Biology Lecture 12: Physical mapping by restriction mapping Saad Mneimneh

Chapter 9. Greedy Technique. Copyright 2007 Pearson Addison-Wesley. All rights reserved.

Week 2 Polygon Triangulation

12 Dynamic Programming (2) Matrix-chain Multiplication Segmented Least Squares

(Refer Slide Time: 01:00)

Lecture 11: Dynamic Programming Steven Skiena. skiena

Dynamic programming II - The Recursion Strikes Back

We ve done. Now. Next

Lecturers: Sanjam Garg and Prasad Raghavendra March 20, Midterm 2 Solutions

Theorem 2.9: nearest addition algorithm

14 Dynamic. Matrix-chain multiplication. P.D. Dr. Alexander Souza. Winter term 11/12

Lecture 20: Satisfiability Steven Skiena. Department of Computer Science State University of New York Stony Brook, NY

Lecture 8: Mergesort / Quicksort Steven Skiena

Memoization/Dynamic Programming. The String reconstruction problem. CS124 Lecture 11 Spring 2018

Polygon Triangulation. (slides partially by Daniel Vlasic )

Efficient Sequential Algorithms, Comp309. Problems. Part 1: Algorithmic Paradigms

CS 532: 3D Computer Vision 14 th Set of Notes

Write an algorithm to find the maximum value that can be obtained by an appropriate placement of parentheses in the expression

Lecture 14: Computational Geometry Steven Skiena. skiena

CS 231: Algorithmic Problem Solving

15-451/651: Design & Analysis of Algorithms January 26, 2015 Dynamic Programming I last changed: January 28, 2015

CSC 373: Algorithm Design and Analysis Lecture 8

Lecture 8. Dynamic Programming

A 0 A 1... A i 1 A i,..., A min,..., A n 1 in their final positions the last n i elements After n 1 passes, the list is sorted.

Exam Sample Questions CS3212: Algorithms and Data Structures

Polygon Triangulation

4.1.2 Merge Sort Sorting Lower Bound Counting Sort Sorting in Practice Solving Problems by Sorting...

6.854J / J Advanced Algorithms Fall 2008

Scribe: Virginia Williams, Sam Kim (2016), Mary Wootters (2017) Date: May 22, 2017

CS 373: Combinatorial Algorithms, Fall Name: Net ID: Alias: U 3 / 4 1

Algorithm Design Techniques part I

Algorithms: COMP3121/3821/9101/9801

Lecture 6: Hashing Steven Skiena

CMPS 102 Solutions to Homework 7

2D rendering takes a photo of the 2D scene with a virtual camera that selects an axis aligned rectangle from the scene. The photograph is placed into

Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest. Introduction to Algorithms

Chapter 3 Dynamic programming

Chapter 8. NP-complete problems

Algorithms for Data Science

COS 226 Algorithms and Data Structures Fall Final Solutions. 10. Remark: this is essentially the same question from the midterm.

CME 305: Discrete Mathematics and Algorithms Instructor: Reza Zadeh HW#3 Due at the beginning of class Thursday 03/02/17

Convex Polygon Generation

Framework for Design of Dynamic Programming Algorithms

Algorithm Design Techniques. Hwansoo Han

CS6100: Topics in Design and Analysis of Algorithms

CS 534: Computer Vision Segmentation and Perceptual Grouping

Lecture 13: Minimum Spanning Trees Steven Skiena. Department of Computer Science State University of New York Stony Brook, NY

Basic Properties The Definition of Catalan Numbers

(Feodor F. Dragan) Department of Computer Science Kent State University. Advanced Algorithms, Feodor F. Dragan, Kent State University 1

Dynamic Programming: 1D Optimization. Dynamic Programming: 2D Optimization. Fibonacci Sequence. Crazy 8 s. Edit Distance

Chain Matrix Multiplication

Dynamic Programming Group Exercises

Chapter 11: Graphs and Trees. March 23, 2008

6. Lecture notes on matroid intersection

Evolutionary tree reconstruction (Chapter 10)

Robert Collins CSE586 CSE 586, Spring 2009 Advanced Computer Vision

Chapter 6. Dynamic Programming

Optimal Region for Binary Search Tree, Rotation and Polytope

Lecture 12: Grids Steven Skiena. skiena

Vertex Cover Approximations

1. (a) O(log n) algorithm for finding the logical AND of n bits with n processors

Polygon Partitioning. Lecture03

Rate-Distortion Optimized Tree Structured Compression Algorithms for Piecewise Polynomial Images

Algorithms Interview Questions

Lecture 13: Minimum Spanning Trees Steven Skiena

Dynamic Programming (Part #2)

Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, Dynamic Programming

Lecture 14: Shortest Paths Steven Skiena

Lecture 13: Chain Matrix Multiplication

Transcription:

Lecture 12: Examples of Dynamic Programming (1997) Steven Skiena Department of Computer Science State University of New York Stony Brook, NY 11794 4400 http://www.cs.sunysb.edu/ skiena

Give an O(n 2 ) algorithm to find the longest montonically increasing sequence in a sequence of n numbers. Build an example first: (5, 2, 8, 7, 1, 6, 4) Ask yourself what would you like to know about the first n 1 elements to tell you the answer for the entire sequence? 1. The length of the longest sequence in s 1, s 2,...,s n 1. (seems obvious) 2. The length of the longest sequence s n will extend! (not as obvious - this is the idea!) Let s i be the length of the longest sequence ending with the ith character:

sequence 5 2 8 7 3 1 6 4 s i 1 1 2 2 2 1 3 3 How do we compute si? s i = max 0<j<i,seq[j]<seq[i] s j + 1 s 0 = 0 To find the longest sequence - we know it ends somewhere, so Length = max n i=1 s i

The Principle of Optimality To use dynamic programming, the problem must observe the principle of optimality, that whatever the initial state is, remaining decisions must be optimal with regard the state following from the first decision. Combinatorial problems may have this property but may use too much memory/time to be efficient.

Example: The Traveling Salesman Problem Let T(i; j 1, j 2,...,j k ) be the cost of the optimal tour for i to 1 that goes thru each of the other cities once T(i; i 1, j 2,...,j i ) = Min 1 m k C[i, j m ] + T(j m ; j 1, j 2,...,j k ) T(i, j) = C(i, j) + C(j, 1) Here there can be any subset of j 1, j 2,...,j k instead of any subinterval - hence exponential. Still, with other ideas (some type of pruning or best-first search) it can be effective for combinatorial search.

When can you use Dynamic Programming? Dynamic programming computes recurrences efficiently by storing partial results. Thus dynamic programming can only be efficient when there are not too many partial results to compute! There are n! permutations of an n-element set we cannot use dynamic programming to store the best solution for each subpermutation. There are 2 n subsets of an n-element set we cannot use dynamic programming to store the best solution for each. However, there are only n(n 1)/2 continguous substrings of a string, each described by a starting and ending point, so we can use it for string problems.

There are only n(n 1)/2 possible subtrees of a binary search tree, each described by a maximum and minimum key, so we can use it for optimizing binary search trees. Dynamic programming works best on objects which are linearly ordered and cannot be rearranged characters in a string, matrices in a chain, points around the boundary of a polygon, the left-to-right order of leaves in a search tree. Whenever your objects are ordered in a left-to-right way, you should smell dynamic programming!

Minimum Length Triangulation A triangulation of a polygon is a set of non-intersecting diagonals which partiions the polygon into diagonals. The length of a triangulation is the sum of the diagonal lengths. We seek to find the minimum length triangulation. For a convex polygon, or part thereof:

k i j Once we identify the correct connecting vertex, the polygon is partitioned into two smaller pieces, both of which must be triangulated optimally! t[i, i + 1] = 0 t[i, j] = min j t[i, k] + t[k, j] + ik + kj k=i Evaluation proceeds as in the matrix multiplication example - ( n 2) values of t, each of which takes O(j i) time if we evaluate the sections in order of increasing size.

1 J-i = 2 13, 24, 35, 46, 51, 62 2 6 J-i = 3 14, 25, 36, 41, 52, 63 3 4 5 J-i = 4 15, 26, 31, 42, 53, 64 Finish with 16 What if there are points in the interior of the polygon?

Dynamic Programming and High Density Bar Codes Symbol Technology has developed a new design for bar codes, PDF-417 that has a capacity of several hundred bytes. What is the best way to encode text for this design? They developed a complicated mode-switching data compression scheme.

ALPHA latch latch shift latch latch LOWER CASE shift latch latch MIXED shift OTHER CHARS Latch commands permanently put you in a different mode. Shift commands temporarily put you in a different mode.

Originally, Symbol used a greedy algorithm to encode a string, making local decisions only. We realized that for any prefix, you want an optimal encoding which might leave you in every possible mode. The Quick Brown Fox Alpha Lower Mixed Punct. X M[i, j] = min(m[i 1, k]+ the cost of encoding the ith character and ending up in node j). Our simple dynamic programming algorithm improved to

capacity of PDF-417 by an average of 8%!

Dynamic Programming and Morphing Morphing is the problem of creating a smooth series of intermediate images given a starting and ending image. The key problem is establishing a correspondence between features in the two images. You want to morph an eye to an eye, not an ear to an ear. We can do this matching on a line-by-line basis: T = 0 Object A s segments T = 0.5 T = 1 Object B s segments

This should sound like string matching, but with a different set of operations: Full run match: We may match run i on top to run j on bottom for a cost which is a function of the difference in the lengths of the two runs and their positions. Merging runs: We may match a string of consecutive runs on top to a run on bottom. The cost will be a function of the number of runs, their relative positions, and lengths. Splitting runs: We may match a big run on top to a string of consecutive runs on the bottom. This is just the converse of the merge. Again, the cost will be a function of the number of runs, their relative positions, and lengths.

This algorithm was incorported into a morphing system, with the following results: