Randomized incremental construction. Trapezoidal decomposition: Special sampling idea: Sample all except one item

Similar documents
Field: We have been doing geometry eg linear programming. But in computational geometry, key difference in focus: low dimension d

Trapezoidal decomposition:

Trapezoidal Maps. Notes taken from CG lecture notes of Mount (pages 60 69) Course page has a copy

(2,4) Trees. 2/22/2006 (2,4) Trees 1

(2,4) Trees Goodrich, Tamassia (2,4) Trees 1

Motivation for B-Trees

Search Trees - 1 Venkatanatha Sarma Y

Search Trees. Undirected graph Directed graph Tree Binary search tree

Lecture 5. Treaps Find, insert, delete, split, and join in treaps Randomized search trees Randomized search tree time costs

Quiz 1 Solutions. (a) f(n) = n g(n) = log n Circle all that apply: f = O(g) f = Θ(g) f = Ω(g)

CS102 Binary Search Trees

Recall: Properties of B-Trees

Computational Optimization ISE 407. Lecture 16. Dr. Ted Ralphs

CS301 - Data Structures Glossary By

CSE100. Advanced Data Structures. Lecture 8. (Based on Paul Kube course materials)

Lecture Summary CSC 263H. August 5, 2016

Computational Geometry

Treaps. 1 Binary Search Trees (BSTs) CSE341T/CSE549T 11/05/2014. Lecture 19

Chapter 15. Binary Search Trees (BSTs) Preliminaries

Binary search trees. Binary search trees are data structures based on binary trees that support operations on dynamic sets.

Line segment intersection. Family of intersection problems

Lecture 3 February 20, 2007

Sorted Arrays. Operation Access Search Selection Predecessor Successor Output (print) Insert Delete Extract-Min

Chapter 2: Basic Data Structures

Lecture 6: Analysis of Algorithms (CS )

Lower Bound on Comparison-based Sorting

Computational Geometry

CSE 530A. B+ Trees. Washington University Fall 2013

Analysis of Algorithms

COMP Analysis of Algorithms & Data Structures

Binary Search Trees, etc.

Balanced Binary Search Trees. Victor Gao

SAMPLING AND THE MOMENT TECHNIQUE. By Sveta Oksen

1 Binary Search Trees (BSTs)

Algorithms in Systems Engineering ISE 172. Lecture 16. Dr. Ted Ralphs

(2,4) Trees Goodrich, Tamassia. (2,4) Trees 1

Orthogonal Range Search and its Relatives

Binary search trees 3. Binary search trees. Binary search trees 2. Reading: Cormen et al, Sections 12.1 to 12.3

Balanced Trees Part Two

An AVL tree with N nodes is an excellent data. The Big-Oh analysis shows that most operations finish within O(log N) time

Solutions to relevant spring 2000 exam problems

Binary Search Trees. Analysis of Algorithms

Parallel and Sequential Data Structures and Algorithms Lecture (Spring 2012) Lecture 16 Treaps; Augmented BSTs

Line Arrangements. Applications

Algorithms. AVL Tree

Lecture 11: Multiway and (2,4) Trees. Courtesy to Goodrich, Tamassia and Olga Veksler

Algorithm Theory. 8 Treaps. Christian Schindelhauer

Binary Heaps in Dynamic Arrays

CIS265/ Trees Red-Black Trees. Some of the following material is from:

CSci 231 Final Review

DATA STRUCTURES AND ALGORITHMS. Hierarchical data structures: AVL tree, Bayer tree, Heap

Binary Search Trees Treesort

CS127: B-Trees. B-Trees

How many leaves on the decision tree? There are n! leaves, because every permutation appears at least once.

CSE 100 Advanced Data Structures

Data Structures and Algorithms Chapter 4

Sample Exam 1 Questions

Data Structures and Algorithms Week 4

An Implementation of a Near-Linear Polygon Triangulation Algorithm for General Polygons

Chapter 6 Heap and Its Application

x-fast and y-fast Tries

COMP Analysis of Algorithms & Data Structures

CS521 \ Notes for the Final Exam

CS2223: Algorithms Sorting Algorithms, Heap Sort, Linear-time sort, Median and Order Statistics

Planar Point Location

Computing intersections in a set of line segments: the Bentley-Ottmann algorithm

Question 7.11 Show how heapsort processes the input:

Lecture: Analysis of Algorithms (CS )

CS 532: 3D Computer Vision 14 th Set of Notes

Rank-Pairing Heaps. Bernard Haeupler Siddhartha Sen Robert E. Tarjan. SIAM JOURNAL ON COMPUTING Vol. 40, No. 6 (2011), pp.

Sorting and Selection

Final Examination CSE 100 UCSD (Practice)

COMP Analysis of Algorithms & Data Structures

SFU CMPT Lecture: Week 9

Jana Kosecka. Red-Black Trees Graph Algorithms. Many slides here are based on E. Demaine, D. Luebke slides

Priority Queues. T. M. Murali. January 26, T. M. Murali January 26, 2016 Priority Queues

Range Minimum Queries Part Two

Heaps. 2/13/2006 Heaps 1

EE 368. Weeks 5 (Notes)

B-Trees. Version of October 2, B-Trees Version of October 2, / 22

x-fast and y-fast Tries

Balanced search trees

Trees. Courtesy to Goodrich, Tamassia and Olga Veksler

Trapezoid and Chain Methods

Introduction to Algorithms March 11, 2009 Massachusetts Institute of Technology Spring 2009 Professors Sivan Toledo and Alan Edelman Quiz 1

Treewidth and graph minors

CSCI2100B Data Structures Heaps

Lecture 5: Sorting Part A

Priority Queues. 1 Introduction. 2 Naïve Implementations. CSci 335 Software Design and Analysis III Chapter 6 Priority Queues. Prof.

GEOMETRIC SEARCHING PART 1: POINT LOCATION

B-Trees. Disk Storage. What is a multiway tree? What is a B-tree? Why B-trees? Insertion in a B-tree. Deletion in a B-tree

Persistent Data Structures

each processor can in one step do a RAM op or read/write to one global memory location

CMSC th Lecture: Graph Theory: Trees.

CSE 417: Algorithms and Computational Complexity. 3.1 Basic Definitions and Applications. Goals. Chapter 3. Winter 2012 Graphs and Graph Algorithms

Splay Trees. (Splay Trees) Data Structures and Programming Spring / 27

Balanced Trees Part One

CMSC 754 Computational Geometry 1

Advanced Set Representation Methods

COMP3121/3821/9101/ s1 Assignment 1

Transcription:

Randomized incremental construction Special sampling idea: Sample all except one item hope final addition makes small or no change Method: process items in order average case analysis randomize order to achieve average case e.g. binary tree for sorting Backwards analysis compute expected time to insert S i 1 S i backwards: time to delete S i S i 1 conditions on S i but generally analysis doesn t care what S i is. Trapezoidal decomposition: Motivation: manipulate/analayze a collection of n segments assume no degeneracy: endpoints distinct (simulate touch by slight crossover) e.g. detect segment intersections e.g., point location data structure Basic idea: Draw verticals at all points and intersects Divides space into slabs binary search on x coordinate for slab binary search on y coordinate inside slab (feasible since lines noncrossing) problem: Θ(n 2 ) space Definition. 1

draw altitudes from each endpoints and intersection till hit a segment. trapezoid graph is planar (no crossing edges) each trapezoid is a face show a face. one face may have many vertices (from altitudes that hit the outside of the face) but max vertex degree is 6 (assuming nondegeneracy) so total space O(n + k) for k intersections. number of faces also O(n + k) (at least one edge/face, at most 2 face/edge) (or use Euler s theorem: n v n e + n f 2) standard clockwise pointer representation lets you walk around a face Randomized incremental construction: to insert segment, start at left endpoint draw altitudes from left end (splits a trapezoid) traverse segment to right endpoint, adding altitudes whenever intersect traverse again, erasing (half of) altitudes cut by segment Implementation clockwise ordering of neighbors allows traversal of a face in time proportional to number of vertices for each face, keep a (bidirectional) pointer to all not-yet-inserted left-endpoints in face to insert line, start at face containing left endpoint traverse face to see where leave it create intersection, update face (new altitude splits in half) update left-end pointers segment cuts some altititudes: destroy half removing altitude merges faces update left-end pointers (note nonmonotonic growth of data structure) 2

Analysis: Overall, update left-end-pointers in faces neighboring new line time to insert s is (n(f) + l(f )) f F (s) where F (s) is faces s bounds after insertion n(f ) is number of vertices on face f boundary l(f ) is number of left-ends inside f. So if S i is first i segments inserted, expected work of insertion i is 1 (n(f) + l(f )) i s Si f F (s) Note each f appears at most 4 times in sum since at most 4 lines define each trapezoid. so O( 1 i f (n(f) + l(f ))). Bound endpoint contribution: note f l(f ) = n i so contributes n/i so total O(n log n) (tight to sorting lower bound) Bound intersection contribution n(f ) is just number of vertices in planar graph So O(k i + i) if k i intersections between segments so far so cost is E[k i ] intersection present if both segments in first i insertions so expected cost is O((i 2 /n 2 )k) so cost contribution (i/n 2 )k sum over i, get O(k) note: adding to RIC, assumption that first i items are random. Total: O(n log n + k) 3

Search structure Starting idea: extend all vertical lines infinitely divides space into slabs binary search to find place in slab binary search in slab feasible since lines in slab have total order O(log n) search time Goal: apply binary search in slabs, without n 2 space Idea: trapezoidal decom is important part of vertical lines problem: slab search no longer well defined but we show ok The structure: A kind of search tree x nodes test against an altitude y nodes test against a segment leaves are trapezoids each node has two children But may have many parents Inserting an edge contained in a trapezoid update trapezoids build a 4-node subtree to replace leaf Inserting an edge that crosses trapezoids sequence of traps Δ i Say Δ 0 has left endpoint, replace leaf with x-node for left endpoint and y-node for new segment Same for last Δ middle Δ: each got a piece cut off 4

cut off piece got merged to adjacent trapezoid Replace each leaf with a y node for new segment two children point to appropriate traps merged trap will have several parents one from each premerge trap. Search time analysis depth increases by one for new trapezoids RIC argument shows depth O(log n) Fix search point q, build data structure Length of search path increased on insertion only if trapezoid containing q changes Odds of top or bottom edge vanishing (backwards analysis) are 1/i Left side vanishes iff unique segment defines that side and it vanishes So prob. 1/i Total O(1/i) for i th insert, so O(log n) overall. Treaps Dictionaries for ordered sets New Operations. enumerate in order successor-of, predecessor-of (even if not in set) join(s, k, T ), split, paste(s, T ) Binary tree. child and parent pointers endogenous: leaf nodes empty. balanced if depth O(log n) average case. worst case Tree balancing rotations (show) implementing operations. red/black, AVL 5

splay trees. drawbacks in geometry: auxiliary structure on nodes in subtree (eg, for remaining dimensions) rebuild on rotation Returning to average case: Assign random arrival orders to keys Build tree as if arrived in that order Average case applies No rotations on searches Choosing priorities define arrival by random priorities assume continuous distribution, fix. eg, use 2 log n bits, w.h.p. no collisions Treaps. tree has keys in heap order of priorities unique tree given priorities follows from insertion order implement insert/delete etc. rotations to maintain heap property Depth d(x) analysis Tree is trace of a quicksort We proved O(log n) w.h.p. lemma: for x rank k, E[d(x)] = H k + H n k+1 1 S = {y S y x} Q x = ancestors of x Show E[Q ] = H k. x to show: y Q iff inserted before all z, y < z x. x deduce: item j away has prob 1/j. Add. Suppose y Q. x 6

Then inserted before x Suppose some z between inserted before y Then y in left subtree of z, x in right, so not ancestor Thus, y before every z Suppose y first then x follows y on all comparisons (no z splits So ends up in subtree of y Rotation analysis Insert/Delete time define spines equal left spine of right sub plus right spine of left sub proof: when rotate up, one spine increments, other stays fixed. R x length of right spine of left subtree E[R x ] = 1 1/k if rank k To show: y R x iff inserted after x but before all z, y < z < x sinceif z before y, then y goes left, so not on spine deduce: if r elts between, r! of (r + 2)! permutations work. So probability 1/(r + 1)(r + 2). Expectation 1/(1 2) + 1/(2 3) + = 1 1/k subtle: do analysis only on elements inserted in real-time before x, but now assume they arrive in random order in virtual priorities. 7