1 Identifying and sorting jordan sequences. 2 Jordan curve Jordan curve in the plane: A continous curve that does not intersect itself 123456789101112131415161718192021.

Slides:



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

Polygon Triangulation
Computational Geometry
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
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
9/12/06CS 6463: AT Computational Geometry1 CS 6463: AT Computational Geometry Fall 2006 Triangulations and Guarding Art Galleries II Carola Wenk.
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.
CS 253: Algorithms Chapter 6 Heapsort Appendix B.5 Credit: Dr. George Bebis.
Single source shortest paths in a simple polygon Guibas, Hershberger, Leven, Sharir, Tarjan (1987)
Analysis of Algorithms CS 477/677
This material in not in your text (except as exercises) Sequence Comparisons –Problems in molecular biology involve finding the minimum number of edit.
ECE 667 Synthesis and Verification of Digital Systems
Important Problem Types and Fundamental Data Structures
Randomized Algorithms - Treaps
CSE53111 Computational Geometry TOPICS q Preliminaries q Point in a Polygon q Polygon Construction q Convex Hulls Further Reading.
CHAPTER 71 TREE. Binary Tree A binary tree T is a finite set of one or more nodes such that: (a) T is empty or (b) There is a specially designated node.
B+ Trees COMP
Binary Trees, Binary Search Trees RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
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.
Agenda Review: –Planar Graphs Lecture Content:  Concepts of Trees  Spanning Trees  Binary Trees Exercise.
Heapsort. What is a “heap”? Definitions of heap: 1.A large area of memory from which the programmer can allocate blocks as needed, and deallocate them.
R-Trees: A Dynamic Index Structure For Spatial Searching Antonin Guttman.
Balanced Search Trees Chapter 19 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Rooted Tree a b d ef i j g h c k root parent node (self) child descendent leaf (no children) e, i, k, g, h are leaves internal node (not a leaf) sibling.
Review Sorting algorithms Selection Sort Insertion Sort Bubble Sort Merge Sort Quick Sort.
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  Average case and worst case Big O for –insertion –deletion –access  Balance is important. Unbalanced trees give worse than log.
9/8/10CS 6463: AT Computational Geometry1 CS 6463: AT Computational Geometry Fall 2010 Triangulations and Guarding Art Galleries Carola Wenk.
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.
1 R-Trees Guttman. 2 Introduction Range queries in multiple dimensions: Computer Aided Design (CAD) Geo-data applications Support special data objects.
CMPS 3130/6130 Computational Geometry Spring 2017
Balanced Search Trees 2-3 Trees AVL Trees Red-Black Trees
Topic 2: binary Trees COMP2003J: Data Structures and Algorithms 2
Andreas Klappenecker [partially based on the slides of Prof. Welch]
Unit 9 Multi-Way Trees King Fahd University of Petroleum & Minerals
Data Structures and Design in Java © Rick Mercer
Red-Black Trees v z Red-Black Trees Red-Black Trees
B-Trees B-Trees.
B-Trees B-Trees.
Advanced Algorithms Analysis and Design
Chapter 25: Advanced Data Types and New Applications
Finger search trees.
Multiway search trees and the (2,4)-tree
B-Trees Disk Storage What is a multiway tree? What is a B-tree?
(edited by Nadia Al-Ghreimil)
Pairing Heaps Actual Complexity.
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
Identifying and sorting jordan sequences
G-trees Region identifier: string of bits built as follows
B-Trees Disk Storage What is a multiway tree? What is a B-tree?
Red-Black Trees v z /17/2019 4:20 PM Red-Black Trees
CSIT 402 Data Structures II With thanks to TK Prasad
B-Trees Disk Storage What is a multiway tree? What is a B-tree?
Binary Trees, Binary Search Trees
Heaps © 2014 Goodrich, Tamassia, Goldwasser Heaps Heaps
Mark Redekopp David Kempe
Heaps & Multi-way Search Trees
Binary Trees, Binary Search Trees
Binary Search Trees < > = Dictionaries
Red-Black Trees v z /6/ :10 PM Red-Black Trees
Presentation transcript:

1 Identifying and sorting jordan sequences

2 Jordan curve Jordan curve in the plane: A continous curve that does not intersect itself

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

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

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

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

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

8 Polygon clipping algorithm

9 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

10 Polygon triangulation Useful for triangulating simple polygons.

11 Applications (cont) Computational geography: Given the sequence of intersections of two jordan curves in the order in which they occur on one of the curves sort them in the order in which they occur on the other curve.

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

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

14 Nested parenthesis (cont) The sequence is a jordan sequence iff different pairs {x 2i-1,x 2i } {x 2j-1,x 2j } cannot cross Cross: either or

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

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

17 The algorithm The algorithm processes x 1,x 2,.....,x n 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 {- , x 1,  } For i = 2,....n process x i as follows Suppose i is even, i.e. {x i-1, x i } is to be added to the upper tree Assume x i-1 < x i (otherwise it is symmetric)

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

19 The algorithm (cont) Case B: l j < x i-1 < x i < r j l j r j x i-1 xixi Make {x i-1, x i } the new last child of {x j-1, x j }. Insert x i after x i-1 in the sorted list

20 The algorithm (cont) Case C: x i-1 < x i < l j l j r j x i-1 xixi Insert {x i-1, x i } into the list of siblings of {x j-1, x j } just before {x j-1, x j } Insert x i after x i-1 in the sorted list

21 The algorithm (cont) Case D: x i-1 < l j < x i l j r j x i-1 In the list of siblings of {x j-1, x j } find the last pair {x k-1, x k } such that l k < x i If r k > x i then it is not a jordan sequence. xixi l k r k

22 The algorithm (cont) Case D: x i-1 < l j < x i l j r j x i-1 Otherwise if {x k-1, x k } is the last child of its parent pair {x p-1, x p } and r p < x i it is not a jordan sequence. xixi l k r k r p l p

23 The algorithm (cont) Case D: x i-1 < l j < x i l j r j x i-1 Remove from the list of siblings of {x j-1, x j } the sublist from {x j-1, x j } to {x k-1, x k } (inclusive) and replace it by {x i-1, x i }. Make the removed sublist the list of children of {x i-1, x i }. Insert x i after r k into the sorted list. xixi l k r k r p l p

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

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

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

27 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. --

28 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})) 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 ?

29 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(x 1 )/x 1 + log(x 2 )/(x 2 ) + … log(x k )/x k The x i decrease exponentially : x i ≤ x i-1 /2 Therefore the sum is at most Σ k/2 k = O(1)

30 Analysis Let T(p,s) be the maximum time it takes to perform p such operations on an initial list of size s. Then T(p,s) = 0 if p = 0 Max { T(i, d+1) + T(p-i-1, s-d+1) + O(1 + log(min{d,s-d} + 1)) } 0  i < p 0  d  s We are interested in 2T(  n/2 ,1) = O(n) T(p,s) = O(p+s)