Identifying and sorting jordan sequences

Slides:



Advertisements
Similar presentations
CS16: Introduction to Data Structures & Algorithms
Advertisements

Polygon Triangulation
Trees Types and Operations
1 Finger search trees. 2 Goal Keep sorted lists subject to the following operations: find(x,L) insert(x,L) delete(x,L) catenate(L1,L2) : Assumes that.
2/3/15CMPS 3130/6130 Computational Geometry1 CMPS 3130/6130 Computational Geometry Spring 2015 Triangulations and Guarding Art Galleries II Carola Wenk.
B+-Trees (PART 1) What is a B+ tree? Why B+ trees? Searching a B+ tree
9/12/06CS 6463: AT Computational Geometry1 CS 6463: AT Computational Geometry Fall 2006 Triangulations and Guarding Art Galleries II Carola Wenk.
Algorithms and Data Structures Lecture 13. Agenda: Plane Geometry: algorithms on polygons - Verification if point belongs to a polygon - Convex hull.
Balanced Search Trees. 2-3 Trees Trees Red-Black Trees AVL Trees.
A balanced life is a prefect life.
B-Trees. Motivation for B-Trees Index structures for large datasets cannot be stored in main memory Storing it on disk requires different approach to.
1 B trees Nodes have more than 2 children Each internal node has between k and 2k children and between k-1 and 2k-1 keys A leaf has between k-1 and 2k-1.
Single source shortest paths in a simple polygon Guibas, Hershberger, Leven, Sharir, Tarjan (1987)
1 Identifying and sorting jordan sequences. 2 Jordan curve Jordan curve in the plane: A continous curve that does not intersect itself
This material in not in your text (except as exercises) Sequence Comparisons –Problems in molecular biology involve finding the minimum number of edit.
1 Efficiently Mining Frequent Trees in a Forest Mohammed J. Zaki.
Important Problem Types and Fundamental Data Structures
Randomized Algorithms - Treaps
B-Tree. B-Trees a specialized multi-way tree designed especially for use on disk In a B-tree each node may contain a large number of keys. The number.
B+ Trees COMP
UNC Chapel Hill M. C. Lin Point Location Reading: Chapter 6 of the Textbook Driving Applications –Knowing Where You Are in GIS Related Applications –Triangulation.
Triangulating a monotone polygon
Introduction n – length of text, m – length of search pattern string Generally suffix tree construction takes O(n) time, O(n) space and searching takes.
Lec 15 Oct 18 Binary Search Trees (Chapter 5 of text)
Chapter 18: Searching and Sorting Algorithms. Objectives In this chapter, you will: Learn the various search algorithms Implement sequential and binary.
15-853Page :Algorithms in the Real World Planar Separators I & II – Definitions – Separators of Trees – Planar Separator Theorem.
Agenda Review: –Planar Graphs Lecture Content:  Concepts of Trees  Spanning Trees  Binary Trees Exercise.
AVL Trees and Heaps. AVL Trees So far balancing the tree was done globally Basically every node was involved in the balance operation Tree balancing can.
1 Binary Search Trees   . 2 Ordered Dictionaries Keys are assumed to come from a total order. New operations: closestKeyBefore(k) closestElemBefore(k)
1 Binary Search Trees  Average case and worst case Big O for –insertion –deletion –access  Balance is important. Unbalanced trees give worse than log.
Chapter 11. Chapter Summary  Introduction to trees (11.1)  Application of trees (11.2)  Tree traversal (11.3)  Spanning trees (11.4)
Chapter 16: Searching, Sorting, and the vector Type.
LINKED LISTS.
UNC Chapel Hill M. C. Lin Geometric Data Structures Reading: Chapter 10 of the Textbook Driving Applications –Windowing Queries Related Application –Query.
CMPS 3130/6130 Computational Geometry Spring 2017
3. Polygon Triangulation
Balanced Search Trees 2-3 Trees AVL Trees Red-Black Trees
Red-Black Trees v z Red-Black Trees Red-Black Trees
Copyright © Cengage Learning. All rights reserved.
B-Trees B-Trees.
Red-Black Trees 5/22/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and.
B-Trees B-Trees.
Advanced Algorithms Analysis and Design
Finger search trees.
Multiway search trees and the (2,4)-tree
(edited by Nadia Al-Ghreimil)
(2,4) Trees 11/15/2018 9:25 AM Sorting Lower Bound Sorting Lower Bound.
Lec 12 March 9, 11 Mid-term # 1 (March 21?)
Red-Black Trees v z /20/2018 7:59 AM Red-Black Trees
Red-Black Trees v z Red-Black Trees Red-Black Trees
Multi-Way Search Trees
Copyright © Cengage Learning. All rights reserved.
Copyright © Cengage Learning. All rights reserved.
(2,4) Trees 12/4/2018 1:20 PM Sorting Lower Bound Sorting Lower Bound.
Forests D. J. Foreman.
Red-Black Trees v z /17/2019 4:20 PM Red-Black Trees
CSIT 402 Data Structures II With thanks to TK Prasad
Binary Trees, Binary Search Trees
(edited by Nadia Al-Ghreimil)
(2,4) Trees 2/28/2019 3:21 AM Sorting Lower Bound Sorting Lower Bound.
Copyright © Cengage Learning. All rights reserved.
Copyright © Cengage Learning. All rights reserved.
Red Black Trees (Guibas Sedgewick 78)
(2,4) Trees /6/ :26 AM (2,4) Trees (2,4) Trees
Mark Redekopp David Kempe
Binary Trees, Binary Search Trees
Binary Search Trees < > = Dictionaries
Red-Black Trees v z /6/ :10 PM Red-Black Trees
CS210- Lecture 13 June 28, 2005 Agenda Heaps Complete Binary Tree
Presentation transcript:

Identifying and sorting jordan sequences

Jordan curve Jordan curve in the plane: A continous curve that does not intersect itself 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

Jordan sequence The sequence x1,x2,.....,xn of the intersection points of a jordan curve C with the x-axis in the order in which they occur on C. 6, 1, 21, 13, 12, 7, 5, 4, 3, 2, 20, 18, 17, 14, 11, 10, 9, 8, 15, 16, 19 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

Our problem An efficient algorithm which would recognize and sort a jordan sequence.

A special case: sort the intersections of an n-sided simple polygon with a line.

Application: Polygon clipping Return the intersection of a polygon with a rectangular window (a collection of polygons)

Polygon clipping Return the intersection of a polygon with a rectangular window (a collection of polygons)

Polygon clipping algorithm

You find the intersections by the order they occur on the polygon. But you also need them by the order they occur on the rectangle

Polygon triangulation Useful for triangulating simple polygons.

Assume to simplify presentation Curve nowhere tangent to the x-axis. Curve start below the x-axis (if not reflect)

Nested parenthesis Each pair {x2i-1 ,x2i} for i = 1,....,n/2 corresponds to part of C going from the x-axis up and back to the x-axis. 6, 1, 21, 13, 12, 7, 5, 4, 3, 2, 20, 18, 17, 14, 11, 10, 9, 8, 15, 16, 19 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

Nested parenthesis (cont) The sequence is a jordan sequence iff different pairs {x2i-1 ,x2i} {x2j-1 ,x2j} cannot cross Cross: either or

Upper and lower trees The parent of {x2i-1 ,x2i} is the “immediate” enclosing pair. This defines a forest . Add {-, } to make it a tree.

Upper and lower trees (example) -  1 6 7 12 13 21 14 17 2 3 4 5 8 9 10 11 15 16 18 20 6, 1, 21, 13, 12, 7, 5, 4, 3, 2, 20, 18, 17, 14, 11, 10, 9, 8, 15, 16, 19 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

The algorithm The algorithm processes x1,x2,.....,xn one at a time building the upper tree, the lower tree, and a list of the points in sorted order. Initialization: Make {-, } the only pair in both trees. Initialize the sorted list to be {-, x1, } For i = 2,....n process xi as follows Suppose i is even, i.e. {xi-1 , xi} is to be added to the upper tree Assume xi-1 < xi (otherwise it is symmetric)

The algorithm (cont) Find the point x that follows xi-1 in the sorted list. Find the pair {xj-1 , xj} in the upper tree such that x  {xj-1 , xj} Let {lj , rj } = {xj-1 , xj} Apply one of the following 4 cases Case A: lj < xi-1 < rj < xi lj xi-1 rj xi Stop, this is not a jordan sequence

The algorithm (cont) Case B: lj < xi-1 < xi < rj lj xi-1 xi Make {xi-1 , xi} the new last child of {xj-1 , xj}. Insert xi after xi-1 in the sorted list

The algorithm (cont) Case C: xi-1 < xi < lj xi-1 xi lj rj Insert {xi-1 , xi} into the list of siblings of {xj-1 , xj} just before {xj-1 , xj} Insert xi after xi-1 in the sorted list

The algorithm (cont) Case D: xi-1 < lj < xi xi lk rk xi-1 lj rj In the list of siblings of {xj-1 , xj} find the last pair {xk-1 , xk} such that lk < xi If rk > xi then it is not a jordan sequence.

The algorithm (cont) Case D: xi-1 < lj < xi lp xi-1 lj rj lk rk rp xi Otherwise if {xk-1 , xk} is the last child of its parent pair {xp-1 , xp} and rp < xi it is not a jordan sequence.

The algorithm (cont) Case D: xi-1 < lj < xi lp xi-1 lj rj lk rk rp Remove from the list of siblings of {xj-1 , xj} the sublist from {xj-1 , xj} to {xk-1 , xk} (inclusive) and replace it by {xi-1 , xi}. Make the removed sublist the list of children of {xi-1 , xi}. Insert xi after rk into the sorted list.

The algorithm (cont) If i is odd we work similarly with the lower tree.

The algorithm (example) 6, 1, 21, 13, 12, 7, 5, 4, 3, 2, 20, 18, 17, 14, 11, 10, 9, 8, 15, 16, 19 - 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21  -  1 6 13 21 7 12 17 18 15 16 19 20 2 3 4 5

The algorithm (example) 6, 1, 21, 13, 12, 7, 5, 4, 3, 2, 20, 18, 17, 14, 11, 10, 9, 8, 15, 16, 19 - 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21  -  1 6 13 21 7 12 2 3 4 5 14 18.5 19 20 15 16 17 18

Representation The sorted list of processed numbers is a doubly linked list. Each list of siblings in the upper or lower trees is represented by a homogenous finger search tree. -  1 6 7 12 13 21 14 17 2 3 4 5 8 9 10 11 15 16 18 20

Analysis Inserting a pair before or after some other pair takes O(1) time. Finding and removing a sublist of d pairs from a list of s pairs takes O(1 + log(min{d,s-d})) On each tree we perform at most n/2 operations of the form “remove a sublist/insert a pair” each costs O(1 + log(min{d,s-d} )) for some 1  d  s if it operates on a list of length s. What is the total time ?

Analysis (Cont) Assume all elements are there to begin with. This would just make the split operations more expensive. Charge the split evenly to the items in the smaller part, if d is the length of the smaller part then each element is charged log(d)/d The total charge per element is at most log(x1)/x1 + log(x2)/(x2) + … log(xk)/xk The xi decrease exponentially : xi ≤ xi-1/2 Therefore the sum is at most Σ k/2k = O(1)