380 likes | 435 Views
Greedy Algorithm to Find Minimum Length Triangulation. CSC6520 Algorithm Graduate Student Project Instructor : Dr. Alexander Zelikovsky Student : Yan Liu Spring 2001. Introduction. Definition of Triangulation
E N D
GreedyAlgorithm to Find Minimum Length Triangulation CSC6520 Algorithm Graduate Student Project Instructor : Dr. Alexander ZelikovskyStudent : Yan Liu Spring 2001
Introduction • Definition of Triangulation -- a set T of chords of a convex polygon P that divide the polygon into disjoint triangles. • Minimum length triangulation(MLT) -- Given a convex polygon P=(v1, …, vn) -- Form Triangles by sides and chords of P. -- Find a triangulation that minimizes the sum of the lengths of the triangles in the triangulations.
Example of triangulating a convex polygon v7 v7 v1 v1 v6 v6 v2 v2 v5 v5 v3 v3 v4 v4 Figure 1. Two ways of triangulating a convex polygon.
Data Structure • Heap – a complete binary tree to hold all of diagonals. -- Build-Heap(E) -- Heapify (E, i) • HeapSort algorithm -- to get the minimum length triangulation. • Remove diagonals from set E. -- Heap-delete(E,i) • Add new diagonals -- Heap-Insert(E)
Algorithms for MLT • Given a convex polygon P(v1…vn) • Find the minimum length triangulation for P(v1…vn) • Algorithms -- Greedy-1 Algorithm -- Greedy Algorithm
Greedy-1 Algorithm for MLT • Step 1. Put all of vertices of convex polygon P into set V. • Step 2. Put all of next-neighbor diagonals into set E. For example, (k, k+2) is the next-neighbor diagonal between the vertices vk and vk+2. • Step 3. Find the minimum diagonal (k, k+2) in E, and insert it into the result set M of the minimum length triangulation of the convex polygon P.
Greedy-1 Algorithm for MLT -- continue • Step 4. Remove the vertex vk+1from set V. • Step 5. Remove all diagonals which are related to the removed vertex in set V in the last step. • Step 6. Update E to add unexisted next- neighbor diagonals for the verticesvk and vk+2 such as (k, k+3), (k+2, k-1). • Step 7. Check if E is NOT empty, go back step 3 to repeat; otherwise return the result M.
Example for Greedy – 1 Algorithm v7 v1 v6 v2 v5 v4 v3 E={ (1,3), (2,4),(3,5),(4,6), (5,7), (6,1), (7,2)} V={v1, v2,v3,v4,v5,v6,v7} M= Ø
Example for Greedy – 1 Algorithm --continue v7 v1 v6 v2 v5 v3 v4 E={(1,3), (2,4),(3,5),(4,6), (5,7), (6,1)} V={v1, v2,v3,v4,v5,v6,v7} M={(7, 2)}
Example for Greedy – 1 Algorithm --continue v7 v1 v6 v2 v5 v3 v4 E={ (1,3),(1,6),(2,4),(3,5),(4,6), (5,7)} V={v2,v3,v4,v5,v6,v7} M={(7, 2)}
Example for Greedy – 1 Algorithm --continue v7 v1 v6 v2 v5 v3 v4 E={(2,4),(3,5),(4,6), (5,7)} V={v2,v3,v4,v5,v6,v7} M={(7, 2)}
Example for Greedy – 1 Algorithm --continue v7 Add new next diagonals v1 v6 v2 v5 v3 v4 E={(2,4),(3,5),(4,6), (5,7), (6,2), (7,3)} V’={v2,v3,v4,v5,v6,v7} M={(7, 2)}
Example for Greedy – 1 Algorithm --continue v7 v1 v6 v2 v5 v3 v4 E={(2,4),(3,5),(4,6), (6,2), (7,3)} V={v2,v3,v4,v5,v6,v7} M={(7, 2), (5,7)}
Example for Greedy – 1 Algorithm --continue v7 v1 v6 v2 v5 v3 v4 E={(2,4),(3,5), (4,6), (6,2), (7,3)} V={v2,v3,v4,v5,v6,v7} M={(7, 2), (5,7) }
Example for Greedy – 1 Algorithm --continue v7 v1 v6 v2 v5 v3 v4 E={(2,4),(3,5), (7,3)} V={v2,v3,v4,v5,v7} M={(7, 2), (5,7)}
Example for Greedy – 1 Algorithm --continue v7 v1 v6 v2 v5 Add new next-diagonals v3 v4 E={(2,4),(3,5), (7,3), (5, 2),(7,4)} V={ v2,v3,v4,v5,v7} M={(7, 2), (5,7)}
Example for Greedy – 1 Algorithm --continue v7 v1 v6 v2 v5 v3 v4 E={(3,5), (5, 2),(7,3), (7,4)} V={ v2,v3,v4,v5,v7} M={(7, 2), (5,7), (2,4)}
Example for Greedy – 1 Algorithm --continue v7 v1 v6 v2 v5 v3 v4 E={(3,5), (7,3), (5, 2),(7,4)} V={ v2,v3,v4,v5,v7} M={(7, 2), (5,7), (2,4)}
Example for Greedy – 1 Algorithm --continue v7 v1 v6 v2 v5 v3 v4 E={ (5, 2), (7,4)} V={ v2,v4,v5,v7} M={(7, 2), (5,7),(2,4)}
Example for Greedy – 1 Algorithm --continue v7 v1 v6 v2 v5 v3 v4 E={ (v5, v2)}V={ v2,v4,v7} M={(7, 2), (5,7),(2,4), (4,7)}
Example for Greedy – 1 Algorithm --continue v7 v1 v6 v2 v5 v3 v4 E={(v5, v2)}V={ v2,v4,v7} M={(7, 2), (5,7),(2,4), (4,7)}
Example for Greedy – 1 Algorithm --continue v7 v1 v6 v2 v5 v3 v4 E= Ø V={ v2,v4,v7} M={(7, 2), (5,7),(2,4), (4,7)}
Greedy Algorithm for MLT • Step 1. Insert all diagonals between any two vertices (exclude any two neighbor vertices on the polygon P) into set E. For example, (i, j) is the diagonal between the vertices v i and v j.
Greedy Algorithm for MLT -- continue • Step 2. Find the minimum diagonal in E and insert it into the result set M of the minimum length triangulation for graph G. • Step 3.Remove those diagonals from E, which cross the chosen minimum diagonal in the last step. • Step 4. Check if E is NOT empty, go back step 2 to repeat; otherwise return the result M.
Example for Greedy Algorithm v7 v1 v6 v2 v5 v4 v3 E={(1,3), (1,4), (1,5), (1,6), (2,4),(2,5),(2,6), (2,7), (3,5),(3,6), (3,7),(4,6), (5,7), (4,6), (4,7) } M= Ø
Example for Greedy Algorithm --continue v7 v1 v6 v2 v5 v4 v3 E={(1,3), (1,4), (1,5), (1,6), (2,4),(2,5),(2,6), (2,7), (3,5),(3,6), (3,7),(5,7), (4,7) } M= {(4,6)}
Example for Greedy Algorithm --continue v7 v1 v6 v2 v5 v4 v3 E={(1,3), (1,4), (1,5), (1,6), (2,4), (2,5), (v2,v6), (2,7), (3,5), (3,6), (3,7), (5,7), (4,7)} M= {(4,6)}
Example for Greedy Algorithm --continue v7 v1 v6 v2 v5 v4 v3 E={(1,3), (1,4), (1,6), (2,4), (2,6), (2,7), (3,6), (3,7),(4,7)} M= { (4,6) }
Example for Greedy Algorithm --continue v7 v1 v6 v2 v5 v4 v3 E={(1,3), (1,4), (1,6), (2,4), (2,6), (3,6), (3,7), (4,7) } M= {(4,6), (2,7)}
Example for Greedy Algorithm --continue v7 v1 v6 v2 v5 v4 v3 E={(1,3), (1,4), (1,6), (2,4), (2,6), (3,6), (3,7), (4,7) } M= {(4,6), (2,7) }
Example for Greedy Algorithm --continue v7 v1 v6 v2 v5 v4 v3 E={(2,4), (2,6), (3,6), (3,7), (4,7)} M= {(4,6), (2,7)}
Example for Greedy Algorithm --continue v7 v1 v6 v2 v5 v4 v3 E={(2,6), (3,6), (3,7), (4,7)} M= {(4,6), (2,7),(2,4)}
Example for Greedy Algorithm --continue v7 v1 v6 v2 v5 v4 v3 E={(2,6), (3,6), (3,7), (4,7)} M= {(4,6), (2,7),(2,4)}
Example for Greedy Algorithm --continue v7 v1 v6 v2 v5 v4 v3 E={(2,6), (4,7)} M={(4,6), (2,7),(2,4)}
Example for Greedy Algorithm --continue v7 v1 v6 v2 v5 v4 v3 E={(4,7)} M= {(4,6), (2,7),(2,4), (2,6)}
Example for Greedy Algorithm --continue v7 v1 v6 v2 v5 v4 v3 E={(4,7)} M= {(4,6), (2,7),(2,4), (2,6)}
Example for Greedy Algorithm --continue v7 v1 v6 v2 v5 v4 v3 E= Ø M= {(4,6), (2,7),(2,4), (2,6)}
Summary • Performance -- Greedy algorithm is between O(n^2) and O(n^3) -- Greedy-1 algorithm is O(nlgn) • Result of MLT -- For a convex polygon P(V), using different algorithms may get different results.