Interval S = [3,10]  {x | 3 ≤ x ≤ 10} Closed segment S = (3,10)  {x | 3 < x < 10} Opened segment S = [3,3]  {3} Point.

Slides:



Advertisements
Similar presentations
Interval Heaps Complete binary tree. Each node (except possibly last one) has 2 elements. Last node has 1 or 2 elements. Let a and b be the elements in.
Advertisements

INTERVAL TREE & SEGMENTATION TREE
Heaps1 Part-D2 Heaps Heaps2 Recall Priority Queue ADT (§ 7.1.3) A priority queue stores a collection of entries Each entry is a pair (key, value)
Augmenting Data Structures Advanced Algorithms & Data Structures Lecture Theme 07 – Part I Prof. Dr. Th. Ottmann Summer Semester 2006.
Dynamic Planar Convex Hull Operations in Near- Logarithmic Amortized Time TIMOTHY M. CHAN.
I/O-Algorithms Lars Arge Fall 2014 September 25, 2014.
1 CSC 427: Data Structures and Algorithm Analysis Fall 2004 Heaps and heap sort  complete tree, heap property  min-heaps & max-heaps  heap operations:
I/O-Algorithms Lars Arge Aarhus University February 27, 2007.
Orthogonal Range Searching-1Computational Geometry Prof. Dr. Th. Ottmann 1 Orthogonal Range Searching 1.Linear Range Search : 1-dim Range Trees 2.2-dimensional.
I/O-Algorithms Lars Arge University of Aarhus March 1, 2005.
I/O-Algorithms Lars Arge Spring 2009 March 3, 2009.
Geometric Data Structures Computational Geometry, WS 2007/08 Lecture 13 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik.
Lecture 11 : More Geometric Data Structures Computational Geometry Prof. Dr. Th. Ottmann 1 Geometric Data Structures 1.Rectangle Intersection 2.Segment.
Priority Queues1 Part-D1 Priority Queues. Priority Queues2 Priority Queue ADT (§ 7.1.3) A priority queue stores a collection of entries Each entry is.
Heaps and heapsort COMP171 Fall 2005 Part 2. Sorting III / Slide 2 Heap: array implementation Is it a good idea to store arbitrary.
AALG, lecture 11, © Simonas Šaltenis, Range Searching in 2D Main goals of the lecture: to understand and to be able to analyze the kd-trees and.
Orthogonal Range Searching I Range Trees. Range Searching S = set of geometric objects Q = query object Report/Count objects in S that intersect Q Query.
1 Geometric Intersection Determining if there are intersections between graphical objects Finding all intersecting pairs Brute Force Algorithm Plane Sweep.
CSCE 3110 Data Structures & Algorithm Analysis Binary Search Trees Reading: Chap. 4 (4.3) Weiss.
Computer Science and Software Engineering University of Wisconsin - Platteville 12. Heap Yan Shi CS/SE 2630 Lecture Notes Partially adopted from C++ Plus.
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.
UNC Chapel Hill M. C. Lin Orthogonal Range Searching Reading: Chapter 5 of the Textbook Driving Applications –Querying a Database Related Application –Crystal.
CS 1031 Tree Traversal Techniques; Heaps Tree Traversal Concept Tree Traversal Techniques: Preorder, Inorder, Postorder Full Trees Almost Complete Trees.
Trees By Charl du Plessis. Contents Basic Terminology Basic Terminology Binary Search Trees Binary Search Trees Interval Trees Interval Trees Binary Indexed.
14/13/15 CMPS 3130/6130 Computational Geometry Spring 2015 Windowing Carola Wenk CMPS 3130/6130 Computational Geometry.
Data Structure & Algorithm II.  Delete-min  Building a heap in O(n) time  Heap Sort.
data ordered along paths from root to leaf
Mehdi Mohammadi March Western Michigan University Department of Computer Science CS Advanced Data Structure.
Outline Priority Queues Binary Heaps Randomized Mergeable Heaps.
Lars Arge Presented by Or Ozery. I/O Model Previously defined: N = # of elements in input M = # of elements that fit into memory B = # of elements per.
2IL50 Data Structures Fall 2015 Lecture 9: Range Searching.
Segment Trees - motivation.  When one wants to inspect a small portion of a large and complex objects. Example: –GIS: windowing query in a map.
Segment Trees Basic data structure in computational geometry. Computational geometry.  Computations with geometric objects.  Points in 1-, 2-, 3-, d-space.
CMSC 341 Introduction to Trees. 2/21/20062 Tree ADT Tree definition –A tree is a set of nodes which may be empty –If not empty, then there is a distinguished.
Prof. Amr Goneid, AUC1 Analysis & Design of Algorithms (CSCE 321) Prof. Amr Goneid Department of Computer Science, AUC Part R3. Priority Queues.
HEAPS. Review: what are the requirements of the abstract data type: priority queue? Quick removal of item with highest priority (highest or lowest key.
CMPS 3130/6130 Computational Geometry Spring 2015
UNC Chapel Hill M. C. Lin Geometric Data Structures Reading: Chapter 10 of the Textbook Driving Applications –Windowing Queries Related Application –Query.
Sorting Lower Bound 4/25/2018 8:49 PM
Geometric Data Structures
Data Structures: Disjoint Sets, Segment Trees, Fenwick Trees
CMPS 3130/6130 Computational Geometry Spring 2017
Heaps 9/13/2018 3:17 PM Heaps Heaps.
CMSC 341 Lecture 13 Leftist Heaps
Priority Queues Linked-list Insert Æ Æ head head
Segment tree and Interval Tree
Interval Heaps Complete binary tree.
Orthogonal Range Searching and Kd-Trees
Objectives Introduce different known sorting algorithms
Data Structures: Segment Trees, Fenwick Trees
(2,4) Trees 11/15/2018 9:25 AM Sorting Lower Bound Sorting Lower Bound.
Priority Queues and Heaps
Part-D1 Priority Queues
Heap Sort The idea: build a heap containing the elements to be sorted, then remove them in order. Let n be the size of the heap, and m be the number of.
Heaps 11/27/ :05 PM Heaps Heaps.
Reporting (1-D) Given a set of points S on the line, preprocess them to build structure that allows efficient queries of the from: Given an interval I=[x1,x2]
© 2013 Goodrich, Tamassia, Goldwasser
Heaps 12/4/2018 5:27 AM Heaps /4/2018 5:27 AM Heaps.
(2,4) Trees 12/4/2018 1:20 PM Sorting Lower Bound Sorting Lower Bound.
Ch. 8 Priority Queues And Heaps
Heap Sort CSE 2011 Winter January 2019.
Merge Sort 2/23/ :15 PM Merge Sort 7 2   7  2   4  4 9
(2,4) Trees 2/28/2019 3:21 AM Sorting Lower Bound Sorting Lower Bound.
CMPS 3130/6130 Computational Geometry Spring 2017
Topic 5: Heap data structure heap sort Priority queue
Merge Sort 4/10/ :25 AM Merge Sort 7 2   7  2   4  4 9
Goals Design decisions Design Insertion
Merge Sort 5/30/2019 7:52 AM Merge Sort 7 2   7  2  2 7
The Heap ADT A heap is a complete binary tree where each node’s datum is greater than or equal to the data of all of the nodes in the left and right.
Heaps 9/29/2019 5:43 PM Heaps Heaps.
Presentation transcript:

Interval S = [3,10]  {x | 3 ≤ x ≤ 10} Closed segment S = (3,10)  {x | 3 < x < 10} Opened segment S = [3,3]  {3} Point

The Problem There are several segments S i = [a i,b i ] Given, static We want to ask Give x Find every segment s i such that x  S i

Stabbing Query Line x Green = reported

Output Sensitive What is the size of the output of stabbing query? O(N)? So, stabbing query is O(N) ?? We says it’s O(K) Where K is the number of output We says it’s O(K) Where K is the number of output

Segment Tree Construction Given int begin[n], int end[n] Operation void create(int n,int *begin, int *end); O(n log n) void query(int x,int *ans,int &n); O(log n + K)

Storage Data A binary Tree Each node contain a set of intervals It use O( n log n ) space

Example of segments s1s1 s2s2 s3s3 s4s4 s5s5

Example of queries s1s1 s2s2 s3s3 s4s4 s5s5 Answer = {2,5}

Example of queries s1s1 s2s2 s3s3 s4s4 s5s5 Answer = {3,4,5}

How it works s1s1 s2s2 s3s3 s4s4 s5s5 {1} {1,2,5} {5}{1,2,5} {2,5} {3,5} {3,4} {3,4,5} Answer may change at the endpoints of segment only

Elementary Intervals (EI) e = array of 2N endpoints of {S i } eg, S 1 = {a 1,b 1 }, S 2 = {a 2,b 2 }, S 3 = {a 3,b 3 } E = [a 1,b 1,a 2,b 2,a 3,b 3 ] E* = Sorted E eg, E* = [a 1,a 2,b 1,a 3,b 2,b 3 ] EI = every interval between each element of E* And every point of E* itself (point is also an interval) sorted Eg, EI = (- ,a 1 ), [a 1,a 1 ], (a 1,a 2 ), [a 2,a 2 ], (a 2,b 1 ), [b 1,b 1 ]… a 1 a 2 b 1 a 3 b 2 b 3

Segment Tree Each leaf= elementary interval s1s1 s2s2 s3s3 s4s4 s5s5

Segment Tree s1s1 s2s2 s3s3 s4s4 s5s5 Each internal node Union of child intervals Each internal node Union of child intervals

Internal Node Construction Construct internal node progressively from bottom to top Pairing adjacent child Notice that child does not intersect! Interval of child is a subset of the interval of the root Hence, Each node in the tree corresponds to an interval Let u be the node I(u) is our the interval associated with the node

Construction s1s1 s2s2 s3s3 s4s4 s5s5

Canonical List Each node, additionally, store a list of input segment The segment is stored in the canonical list of node u only when I(u) is a subset of the segment Do not store in the children if the parent has it

Canonical List s1s1 s2s2 s3s3 s4s4 s5s5 s1s1 s1s1 s1s1 S 2, S 5 S5S5 S3S3 S 3,S 4 S3S3 S4S4

Tree Summary Given segments, we can construct tree Each leaves is the elementary interval Each internal node is the union of the leaves i.e., each node is associated with an interval Each node stores “canonical list”, a list of segment that “cover” the interval i.e., the interval is a subset of the segment Do not store in the children

Answering Stabbing Query Start at root Recursively go through child that intersect the query Report everything in canonical list of node in the path O( log n )

Construction of the Canonical List Construct a tree first, without any canonical list Insert every segment into the list Insertion each segment Start at root node Recursively process children that the segment intersect If the interval of each node is a subset of the segment, store the segment into the canonical list

Tree Structure Use Heap style Because the structure of the tree does not change

Query Code void query(node u,float x, int *ans, int &count) { append_canonical(u,ans,n); if u.isLeaf() == false if is_intersect(x, interval( u.left ) ) query(u.left,x,ans, count); else query(u.right,x,ans, count); }

Create void create(int n, int *begin, int *end) { CreateTree(n,begin,end); for (int i = 0;i < n;i++) { insert(root, segment(begin[i],end[i] ); }

Insert Code void insert(node u,segment s) { if is_subset(interval(u),s) store_canonical(u,s) else { if is_intersect(s, interval( u.left ) ) insert(u.left,s); if is_intersect(s, interval( u.right ) ) insert(u.right,s); }

RMQ problem Given an array A of integer What is the minimal value in A[i].. A[k]?

RMQ naïve A[0]A[1]A[2]A[3]A[4]A[5]A[6]A[7]A[8]A[9] min(2,7) = a[5] Preprocess = O(N 2 ) Query = O(1)

RMQ better A[0]A[1]A[2]A[3]A[4]A[5]A[6]A[7]A[8]A[9] min(2,7) = min(M[1], A[2], A[6],A[7]) Preprocess = O(N) Query = O(N 0.5 ) M[0] = A[0]M[3]M[1] = A[5]M[2] = A[6]

RMQ segment Tree Preprocess = O(N log N) Query = O(log N) [0,9] [0,4][5,9] [0,2][3,4] [5,7][8,9] [0,1][2][3][4][5,6][7][8][9] [0][1] [5][6] A segment tree for the interval [0, 9]