Design and Analysis of Algorithms - - PDF document

design and analysis of algorithms
SMART_READER_LITE
LIVE PREVIEW

Design and Analysis of Algorithms - - PDF document

Design and Analysis of Algorithms


slide-1
SLIDE 1

Design and Analysis of Algorithms

. . ก ก ก 2542

http://www.cp.eng.chula.ac.th/faculty/spj

ก ก กกก

Dynamic Programming

Optimal Polygon Triangulation

http://www.cp.eng.chula.ac.th/faculty/spj

Outline

Optimal Polygon Triangualation Problem Polygon Triangulation and Parenthesization Optimal Polygon Triangulation and Matrix-Chain Multiplication

http://www.cp.eng.chula.ac.th/faculty/spj

Optimal Polygon Triangulation

Input Output

http://www.cp.eng.chula.ac.th/faculty/spj

Triangulations

slide-2
SLIDE 2

http://www.cp.eng.chula.ac.th/faculty/spj

Optimal Polygon Triangulation

Input : a convex polygon P = < v0, v0, ..., vn-1 >, a weight function w defined on triangles formed by sides and chords of P. e.g., w( vi vj vk ) = |vi vj| + |vj vk| + |vk vi| Output : find a triangulation that minimizes the sum of the weights of the triangles in the triangulation.

http://www.cp.eng.chula.ac.th/faculty/spj

Triangulation

Parenthesization

v6 v0 v1 v2 v3 v4 v5 A1 A2 A3 A4 A5 A6

http://www.cp.eng.chula.ac.th/faculty/spj

Triangulation

Parenthesization

v6 v0 v1 v2 v3 v4 v5 A1 A2 A3 A4 A5 A6

http://www.cp.eng.chula.ac.th/faculty/spj

Triangulation

Parenthesization

v0 v1 v2 v3 v4 A1 A2 A3 A4 A5 A6

http://www.cp.eng.chula.ac.th/faculty/spj

Triangulation

Parenthesization

v0 v1 v2 v3 v4 A1 A2 A3 A4 A5 A6

http://www.cp.eng.chula.ac.th/faculty/spj

Triangulation

Parenthesization

v2 v3 v4 A1 A2 A3 A4 A5 A6

slide-3
SLIDE 3

http://www.cp.eng.chula.ac.th/faculty/spj

Triangulation

Parenthesization

A1 A2 A3 A4 A5 A6 ( ( ( A1A2)( A3A4 ) ) (A5A6 ) ) A1 A2 A3 A4 A5 A6

http://www.cp.eng.chula.ac.th/faculty/spj

Matrix-Chain Multiplication

Matrix-Chain-Order( p, n ) { for i = 1 to n m[i,i] = 0 for len = 2 to n for i = 1 to n - len + 1 j = i + len - 1 m[i,j] = for k = i to j-1 q = m[i,k] + m[k+1,j] + p[i-1]*p[k]*p[j] if q < m[i,j] then m[i,j] = q s[i,j] = k return s }

http://www.cp.eng.chula.ac.th/faculty/spj

Optimal Polygon Triangulation

Polygon_Triangulate( v, n ) { for i = 1 to n m[i,i] = 0 for len = 2 to n for i = 1 to n - len + 1 j = i + len - 1 m[i,j] = for k = i to j-1 q = m[i,k] + m[k+1,j] + w(v[i-1],v[k],v[j]) if q < m[i,j] then m[i,j] = q s[i,j] = k return s }