Segment Trees Basic data structure in computational geometry. Computational geometry.  Computations with geometric objects.  Points in 1-, 2-, 3-, d-space.

Slides:



Advertisements
Similar presentations
Introduction to Algorithms
Advertisements

AA Trees another alternative to AVL trees. Balanced Binary Search Trees A Binary Search Tree (BST) of N nodes is balanced if height is in O(log N) A balanced.
Digital Search Trees & Binary Tries Analog of radix sort to searching. Keys are binary bit strings.  Fixed length – 0110, 0010, 1010,  Variable.
6/14/2015 6:48 AM(2,4) Trees /14/2015 6:48 AM(2,4) Trees2 Outline and Reading Multi-way search tree (§3.3.1) Definition Search (2,4)
© 2004 Goodrich, Tamassia Binary Search Trees   
Binary Search Trees1 Part-F1 Binary Search Trees   
Geometric Data Structures Computational Geometry, WS 2007/08 Lecture 13 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik.
I/O-Algorithms Lars Arge Aarhus University March 5, 2008.
Trees and Red-Black Trees Gordon College Prof. Brinton.
AVL trees. AVL Trees We have seen that all operations depend on the depth of the tree. We don’t want trees with nodes which have large height This can.
Lecture 11 : More Geometric Data Structures Computational Geometry Prof. Dr. Th. Ottmann 1 Geometric Data Structures 1.Rectangle Intersection 2.Segment.
Chapter 9 contd. Binary Search Trees Anshuman Razdan Div of Computing Studies
B-Trees (continued) Analysis of worst-case and average number of disk accesses for an insert. Delete and analysis. Structure for B-tree node.
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.
UNC Chapel Hill M. C. Lin Orthogonal Range Searching Reading: Chapter 5 of the Textbook Driving Applications –Querying a Database Related Application –Crystal.
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.
AVL Trees Neil Ghani University of Strathclyde. General Trees Recall a tree is * A leaf storing an integer * A node storing a left subtree, an integer.
Analysis of Red-Black Tree Because of the rules of the Red-Black tree, its height is at most 2log(N + 1). Meaning that it is a balanced tree Time Analysis:
10/20/2015 2:03 PMRed-Black Trees v z. 10/20/2015 2:03 PMRed-Black Trees2 Outline and Reading From (2,4) trees to red-black trees (§9.5) Red-black.
© 2004 Goodrich, Tamassia Red-Black Trees v z.
Min Chen School of Computer Science and Engineering Seoul National University Data Structure: Chapter 8.
Search Trees. Binary Search Tree (§10.1) A binary search tree is a binary tree storing keys (or key-element pairs) at its internal nodes and satisfying.
Binary Search Trees   . 2 Binary Search Tree Properties A binary search tree is a binary tree storing keys (or key-element pairs) at its.
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.
CIS 068 Welcome to CIS 068 ! Lesson 12: Data Structures 3 Trees.
(2,4) Trees1 What are they? –They are search Trees (but not binary search trees) –They are also known as 2-4, trees.
Lecture 9COMPSCI.220.FS.T Lower Bound for Sorting Complexity Each algorithm that sorts by comparing only pairs of elements must use at least 
Priority Search Trees Keys are pairs (x,y). Basic (search, insert, delete) and rectangle operations. Two varieties.  Based on a balanced binary search.
CMPS 3130/6130 Computational Geometry Spring 2015
Question 4 Tutorial 8. Part A Insert 20, 10, 15, 5,7, 30, 25, 18, 37, 12 and 40 in sequence into an empty binary tree
Tree Representation and Terminology Binary Trees Binary Search Trees Pointer-Based Representation of a Binary Tree Array-Based Representation of a Binary.
What is a Tree? Formally, we define a tree T as a set of nodes storing elements such that the nodes have a parent-child relationship, that satisfies the.
Lecture 23 Red Black Tree Chapter 10 of textbook
Binary Search Trees < > =
AA Trees.
Red-Black Trees v z Red-Black Trees Red-Black Trees
Red-Black Trees 5/17/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and.
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.
Binary Search Trees < > =
Binary Search Trees Rem Collier Room A1.02
CMPS 3130/6130 Computational Geometry Spring 2017
Binary search tree. Removing a node
Red Black Trees
Chapter 10 Search Trees 10.1 Binary Search Trees Search Trees
AVL DEFINITION An AVL tree is a binary search tree in which the balance factor of every node, which is defined as the difference between the heights of.
Red-Black Trees v z Red-Black Trees 1 Red-Black Trees
Binary Search Tree Chapter 10.
Chapter 10.1 Binary Search Trees
Section 8.1 Trees.
Digital Search Trees & Binary Tries
CMPS 3130/6130 Computational Geometry Spring 2017
KD Tree A binary search tree where every node is a
Priority Search Trees Keys are pairs (x,y).
Red-Black Trees v z Red-Black Trees 1 Red-Black Trees
Binary Search Trees < > =
Red-Black Trees v z /20/2018 7:59 AM Red-Black Trees
Red-Black Trees v z Red-Black Trees Red-Black Trees
Segment Trees Basic data structure in computational geometry.
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]
Digital Search Trees & Binary Tries
2-3-4 Trees Red-Black Trees
Red-Black Trees v z /17/2019 4:20 PM Red-Black Trees
Lecture 36 Section 12.2 Mon, Apr 23, 2007
Binary Search Trees < > =
CMPS 3130/6130 Computational Geometry Spring 2017
Binary Search Trees < > =
Basic Data Structures - Trees
(2,4) Trees /6/ :26 AM (2,4) Trees (2,4) Trees
Red-Black Trees v z /6/ :10 PM Red-Black Trees
Presentation transcript:

Segment Trees Basic data structure in computational geometry. Computational geometry.  Computations with geometric objects.  Points in 1-, 2-, 3-, d-space. Closest pair of points. Nearest neighbor of given point.  Lines in 1-, 2-, 3-, d-space. Machine busy intervals. IP router-table filters (10*, [20, 60]).

Segment Trees  Rectangles or more general polygons in 2-space. VLSI mask verification. Sentry location. 2-D firewall filter. –(source address, destination address) –(10*, 011*) –When addresses are 4 bits long this filter matches addresses in the rectangle ([8,11], [6,7]) Source address

Segment Tree Application Store intervals of the form [i,j], i < j, i and j are integers.  [i,j] may, for example represent the fact that a machine is busy from time i to time j. Answer queries of the form: which intervals intersect/overlap with a given unit interval [a,a+1].  List all machines that are busy from 2 to 3.

Segment Tree – Definition Binary tree. Each node, v, represents a closed interval.  s(v) = start of v’s range.  e(v) = end of v’s range.  s(v) < e(v).  s(v) and e(v) are integers.  Root range = [1,n]. e(v) = s(v) + 1 => v is a leaf node (unit interval). e(v) > s(v) + 1 =>  Left child range is [s(v), (s(v) + e(v))/2].  Right child range is [(s(v) + e(v))/2, e(v)].

Example – Root range = [1,13] 1,13 1,7 7,13 1,44,7 7,1010,13 1,22,4 2,33,4 4,55,75,66,77,88,1010,1111,13 11,1212,138,99,10 Cream colored boxes are leaves/unit intervals.

Store Interval [3,11] 1,13 1,7 7,13 1,44,77,1010,13 1,22,4 2,33,4 4,55,7 5,66,7 7,88,1010,1111,13 11,1212,138,99,10 Unit intervals of [3,11] highlighted. Each interval [i,j], i < j, is stored in one or more nodes of the segment tree. 1,22,4 2,33,4 4,55,7 5,66,7 7,88,1010,1111,13 11,1212,138,99,10

Store Interval [3,11] 1,13 1,7 7,13 1,44,77,1010,13 1,22,4 2,33,4 4,55,7 5,66,7 7,88,1010,1111,13 11,1212,138,99,10 [3,11] is stored in node p iff all leaves in the subtree rooted at p are highlighted and no ancestor of p satisfies this property. 1,22,4 2,33,4 4,55,7 5,66,7 7,88,1010,1111,13 11,1212,138,99,10 3,4 4,77,10 10,11

Store Interval [4,10] 1,13 1,7 7,13 1,44,77,1010,13 1,22,4 2,33,4 4,55,7 5,66,7 7,88,1010,1111,13 11,1212,138,99,10 Each node of a segment tree contains 0 or more intervals. 1,22,4 2,3 4,55,7 5,66,7 7,88,1011,13 11,1212,138,99,10 4,77,10

Which Nodes Are Stored? Need to store only those nodes that contain intervals plus the ancestors of these nodes. 1,13 1,7 7,13 1,44,77,1010,13 1,22,4 2,33,4 4,55,7 5,66,7 7,88,1010,1111,13 11,1212,138,99,10 1,22,4 2,33,4 4,55,7 5,66,7 7,88,1010,1111,13 11,1212,138,99,103,4 4,77,10 10,11

Segment Tree Height Range = [1,n] => Height <= ceil(log 2 (n-1)) ,13 1,7 7,13 1,44,77,1010,13 1,22,4 2,33,4 4,55,7 5,66,7 7,88,1010,1111,13 11,1212,138,99,10 1,22,4 2,33,4 4,55,7 5,66,7 7,88,1010,1111,13 11,1212,138,99,103,4 4,77,10 10,11

Properties [i,j] in node v => [i,j] not in any ancestor of v. 1,13 1,7 7,13 1,44,77,1010,13 1,22,4 2,33,4 4,55,7 5,66,7 7,88,1010,1111,13 11,1212,138,99,103,4 4,77,10 10,11

Properties [i,j] in node v => [i,j] not in sibling of v. 1,13 1,7 7,13 1,44,77,1010,13 1,22,4 2,33,4 4,55,7 5,66,7 7,88,1010,1111,13 11,1212,138,99,103,4 4,77,10 10,11

Properties [i,j] may be in at most 2 nodes at any level. 1,13 1,7 7,13 1,44,77,1010,13 1,22,4 2,33,4 4,55,7 5,66,7 7,88,1010,1111,13 11,1212,138,99,103,4 4,77,10 10,11 Each interval is in O(log n) nodes.

Top-Down Insert — [3,11] 1,13 1,7 7,13 1,44,77,1010,13 1,22,4 2,33,4 4,55,7 5,66,7 7,88,1010,1111,13 11,1212,138,99,10 3,4 4,77,10 10,11

Top-Down Insert insert(s, e, v) {// insert [s,e] into subtree rooted at v if (s <= s(v) && e(v) <= e) add [s,e] to v; // interval spans node range else { if (s < (s(v) + e(v))/2) insert(s,e,v.leftChild); if (e > (s(v) + e(v))/2) insert(s,e,v.rightChild); }

Complexity Of Insert 1,13 1,7 7,13 1,44,77,1010,13 1,22,4 2,33,4 4,55,7 5,66,7 7,88,1010,1111,13 11,1212,138,99,10 Let L and R, respectively, be the leaves for [s,s+1] and [e – 1,e]. 1,22,4 2,33,4 4,55,7 5,66,7 7,88,1010,1111,13 11,1212,138,99,10 3,4 10,11

Complexity Of Insert In the worst-case, L, R, all ancestors of L and R, and possibly the other child of each of these ancestors are visited. 1,13 1,7 7,13 1,44,77,1010,13 1,22,4 2,33,4 4,55,7 5,66,7 7,88,1010,1111,13 11,1212,138,99,10 1,22,4 2,33,4 4,55,7 5,66,7 7,88,1010,1111,13 11,1212,138,99,103,4 10,11          

Complexity Of Insert Complexity is O(log n). 1,13 1,7 7,13 1,44,77,1010,13 1,22,4 2,33,4 4,55,7 5,66,7 7,88,1010,1111,13 11,1212,138,99,10 1,22,4 2,33,4 4,55,7 5,66,7 7,88,1010,1111,13 11,1212,138,99,103,4 10,11          

Top-Down Delete delete(s, e, v) {// delete [s,e] from subtree rooted at v if (s <= s(v) && e(v) <= e) delete [s,e] from v; // interval spans node range else { if (s < (s(v) + e(v))/2) delete(s,e,v.leftChild); if (e > (s(v) + e(v))/2) delete(s,e,v.rightChild); }

Search – [a,a+1] Follow the unique path from the root to the leaf node for the interval [a,a+1]. Report all segments stored in the nodes on this unique path. No segment is reported twice, because no segment is stored in both a node and the ancestor of this node.

Search – [5,6] 1,13 1,7 7,13 1,44,77,1010,13 1,22,4 2,33,4 4,55,7 5,66,7 7,88,1010,1111,13 11,1212,138,99,10  5,6     O(log n + s), where s is the # of segments in the answer.