CS 372: Computational Geometry Lecture 3 Line Segment Intersection
|
|
- Brianne Barnett
- 6 years ago
- Views:
Transcription
1 CS 372: Computational Geometry Lecture 3 Line Segment Intersection Antoine Vigneron King Abdullah University of Science and Technology September 9, 2012 Antoine Vigneron (KAUST) CS 372 Lecture 3 September 9, / 32
2 1 Introduction 2 Preliminary 3 Intersection Detection 4 Intersection reporting Antoine Vigneron (KAUST) CS 372 Lecture 3 September 9, / 32
3 Problems Input: A set S = {s 1, s 2,... s n } of n line segments in R 2 given by the coordinates of their endpoints. s 4 s 1 s 5 s 3 s 2 s 6 Intersection detection: Is there a pair (s i, s j ) S 2 such that i j and s i s j? Intersection reporting: Find all pairs (s i, s j ) S 2 such that i j and s i s j. Antoine Vigneron (KAUST) CS 372 Lecture 3 September 9, / 32
4 Motivation Motion planning: collision detection Antoine Vigneron (KAUST) CS 372 Lecture 3 September 9, / 32
5 Motivation Geographic Information Systems: Map overlay More generally: spatial join in databases ROAD MAP Antoine Vigneron (KAUST) CS 372 Lecture 3 September 9, / 32
6 Motivation Geographic Information Systems: Map overlay More generally: spatial join in databases ROAD MAP + RIVER MAP Antoine Vigneron (KAUST) CS 372 Lecture 3 September 9, / 32
7 Motivation Computer Aided Design: boolean operations P Q P \ Q Antoine Vigneron (KAUST) CS 372 Lecture 3 September 9, / 32
8 Intersection of Two Line Segments Finding the intersection of two line segments: Find the intersection of their two support lines Linear system, two variables, two equations. Check whether this intersection point is between the two endpoints of each line segment. If not, the intersection is empty. Degenerate case: same support line. Intersection may be a line segment. O(1) time. Checking whether two line segments intersect without computing the intersection point: 4 CCW ( ) tests. (How?) Antoine Vigneron (KAUST) CS 372 Lecture 3 September 9, / 32
9 First Approach Brute force algorithm: Check all pairs of segments for intersection. Running time: ( n 2 ) Θ(1) = Θ(n 2 ) Can we do better? Intersection detection: Yes, see later. Intersection reporting: If all pairs intersect there are Ω(n 2 ) intersections, then our time bound is optimal as a function of n. So we will look for an output-sensitive algorithm. Antoine Vigneron (KAUST) CS 372 Lecture 3 September 9, / 32
10 Plane Sweep Algorithms Intuition: A vertical line sweeps the plane from left to right and draws the picture. Example: last week s convex hull algorithm. Current event point I know the upper hull Not handled yet Sweep line Antoine Vigneron (KAUST) CS 372 Lecture 3 September 9, / 32
11 Plane Sweep Algorithms The sweep line moves from left to right and stops at event points. Convex hull: The event points are just the input points. Sometimes they are not known from the start (see intersection reporting). We maintain invariants. Convex hull: I know the upper hull of the points to the left of the sweep line. At each event, restore the invariants. Antoine Vigneron (KAUST) CS 372 Lecture 3 September 9, / 32
12 General Position Assumptions No three endpoints are collinear. Let E be the set of the endpoints. Let I be the set of intersection points. No two points in E I have same x-coordinate. No three segments intersect at the same point. Degenerate Cases s s 3 collinear endpoints same x-coordinate multiple intersection Antoine Vigneron (KAUST) CS 372 Lecture 3 September 9, / 32
13 Intersection Detection Plane sweep algorithm Let l t be the vertical line with equation x = t. S t is the sequence of segments that intersect l t, ordered by the y-coordinates of their intersections with l t. S t = (s 4, s 5, s 3 ) s 1 s 3 s 7 s 2 s 5 s 6 s 4 l t Antoine Vigneron (KAUST) CS 372 Lecture 3 September 9, / 32
14 Intersection Detection Idea: Maintain S t while l t moves from left to right until an intersection is found. Invariants: There is no intersection to the left of lt. We know St. Let t 1 < t 2 < < t 2n be the x-coordinates of the endpoints. l t stops at each time t = t i. Let f be the last index the sweep-line l ti reaches. In other words, let f be the largest index such that there is no intersection point with abscissa smaller than t f. Antoine Vigneron (KAUST) CS 372 Lecture 3 September 9, / 32
15 Example No intersection l tf = l t7 l tf +1 Leftmost intersection Knowing S ti slides.) for some i < f, we can easily find S ti+1. (See next two Antoine Vigneron (KAUST) CS 372 Lecture 3 September 9, / 32
16 First Case: Left Endpoint If t i+1 corresponds to the left endpoint of s, insert s into S ti obtain S ti+1. in order to s 4 s 1 St3 = (s 2, s 3, s 1 ) s 2 s 5 s 3 S t4 = (s 2, s 3, s 4, s 1 ) l t3 l t4 Antoine Vigneron (KAUST) CS 372 Lecture 3 September 9, / 32
17 Second Case: Right Endpoint Delete the corresponding segment in order to obtain S ti+1. s 4 s 1 S t4 = (s 2, s 3, s 4, s 1 ) s 2 s 5 s 3 S t5 = (s 2, s 3, s 4 ) l t4 l t5 Antoine Vigneron (KAUST) CS 372 Lecture 3 September 9, / 32
18 Data Structure We maintain S t in a balanced binary search tree. For i < f, we obtain S ti+1 from S ti by performing an insertion or a deletion. Each takes O(log n) time. We did not check intersections. How to do it? Antoine Vigneron (KAUST) CS 372 Lecture 3 September 9, / 32
19 A Geometric Observation Let q = s s be the leftmost intersection point. s q s l tf = l t7 l tf +1 s and s are adjacent in S tf (proof next slide). Antoine Vigneron (KAUST) CS 372 Lecture 3 September 9, / 32
20 Proof by Contradiction Assume that S tf = (... s... s... s... ). The right endpoint of s cannot be to the left of q, by definition of t f. If q is below s, then s intersect s to the left of q, which contradicts the fact that q is the leftmost intersection. Similarly, q cannot be above s. We reached a contradiction. Antoine Vigneron (KAUST) CS 372 Lecture 3 September 9, / 32
21 Checking Intersection We store S t in a balanced binary search tree T, the order is the vertical order along l t. Given a segment in T, we can find in O(log n) time the next and previous segment in vertical order. When deleting a segment in T, two segments s and s become adjacent. We can find them in O(log n) time and check if they intersect. When inserting a segment s i in T, it becomes adjacent to (at most) two segments s and s. Check if s i s and if s i s. In any case, if we find an intersection, we are done. Antoine Vigneron (KAUST) CS 372 Lecture 3 September 9, / 32
22 Pseudocode Line segment intersection dectection Algorithm DetectIntersection(S) Input: A set S of line segments in R 2 Output: TRUE iff there exist two intersecting segments in S 1. (e 1, e 2... e 2n ) Endpoints, ordered by increasing x-coordinate 2. T empty balanced BST 3. for i = 1 to 2n 4. if e i is left endpoint of some s S 5. then insert s into T 6. if s intersects next(s) or prev(s) 7. then return TRUE 8. if e i is right endpoint of some s S 9. if next(s) intersects prev(s) 10. then return TRUE 11. else delete s from T 12. return FALSE Antoine Vigneron (KAUST) CS 372 Lecture 3 September 9, / 32
23 Analysis Line 1: Θ(n log n) time by mergesort Line 2: O(1) time Line 5 and 6: O(log n) time Loop 3 11: O(n log n) time So our algorithm runs in Θ(n log n) time We will see later that it is optimal in some sense. Antoine Vigneron (KAUST) CS 372 Lecture 3 September 9, / 32
24 Intersection Reporting Brute force: Θ(n 2 ) time, which is optimal in the worst case, when there are k = Ω(n 2 ) intersections. If there is 1 intersection, the detection algorithm does it in O(n log n) time which is better. We will be able to interpolate between these two algorithms, and find an output-sensitive algorithm. Antoine Vigneron (KAUST) CS 372 Lecture 3 September 9, / 32
25 Output Sensitive Algorithm Let k = #intersecting pairs. Here k = # intersection points, since we assume general position. k is the output size. Sweep line algorithm reports intersections in O((n + k) log n) time (see later). This is an output sensitive algorithm. Ω(n + k) is a lower bound nearly optimal (within an O(log n) factor). Antoine Vigneron (KAUST) CS 372 Lecture 3 September 9, / 32
26 Algorithm Similar to intersection detection. Two types of event points: endpoints and intersection points. We do not know intersection points in advance. We cannot sort them all in advance. We will use an event queue Q. Q contains event points ordered by increasing x-coordinate. Implementation: a min-heap. We can insert an event point in O(log n) time. We can dequeue the event point with smallest x-coordinate in O(log n) time. Antoine Vigneron (KAUST) CS 372 Lecture 3 September 9, / 32
27 Algorithm Initially, Q contains all the endpoints. The sweep line moves from left to right. It stops at each event point of Q. When it does, we dequeue the corresponding event point. Each time we find an intersection, we insert it into Q. When we reach an intersection point, we swap the corresponding segments in T, and check for intersection the newly adjacent segments. Antoine Vigneron (KAUST) CS 372 Lecture 3 September 9, / 32
28 Intersection Event s 1 s 2 s 4 s 3 S t = (s 5, s 2, s 3, s 4 ) s 5 S t = (s 5, s 3, s 2, s 4 ) l t l t Check s 4 s 2 and s 3 s 5 At time t, the event queue Q contains all the endpoints with abscissa larger than t and the intersection point s 2 s 3. At time t, we insert s 3 s 5 into Q. Antoine Vigneron (KAUST) CS 372 Lecture 3 September 9, / 32
29 Analysis Each event is inserted or deleted in O(log(n + k)) time. Problem: An intersection point may be inserted several times into Q. s 1 s 2 is inserted three times. - when we reach the left endpoint of s 2 s 2 - when we reach the right endpoint of s 3 - when we reach the right endpoint of s 4 s 3 s 4 s 1 When we reach an event point that is present several times in Q, we just extract it repeatedly until a new event is found. Antoine Vigneron (KAUST) CS 372 Lecture 3 September 9, / 32
30 Analysis Some intersection points are inserted several times into Q. How many times does it happen? At most twice at each endpoint or intersection point. At most 4n + 2k times in total. It follows that we insert O(n + k) events into Q. So the algorithm runs in O((n + k) log(n + k)) time. log(n + k) < log(n + n 2 ) = O(log n) The running time is O((n + k) log n). Antoine Vigneron (KAUST) CS 372 Lecture 3 September 9, / 32
31 Space Complexity In the worst case, Q contains O(n + k) points. This algorithm requires O(n + k) space. Can we do better? Yes: At time t, only keep intersections between segments that are adjacent in S t. Then the algorithm requires only O(n) space. Antoine Vigneron (KAUST) CS 372 Lecture 3 September 9, / 32
32 Conclusion New algorithmic paradigm: Plane Sweep. Idea: a sweep line moves from left to right and draws the picture. It stops at a finite set of event points, where the data structure is updated. The event points are stored in a priority queue. It can be used for other problems. For instance: Map overlay: compute a full description of the map. Fixed-radius near neighbor searching in 2D. Antoine Vigneron (KAUST) CS 372 Lecture 3 September 9, / 32
CS 372: Computational Geometry Lecture 10 Linear Programming in Fixed Dimension
CS 372: Computational Geometry Lecture 10 Linear Programming in Fixed Dimension Antoine Vigneron King Abdullah University of Science and Technology November 7, 2012 Antoine Vigneron (KAUST) CS 372 Lecture
More informationComputational Geometry
for map overlay Lecture 2: for map overlay 1 Map layers Map overlay In a geographic information system (GIS) data is stored in separate layers A layer stores the geometric information about some theme,
More informationIntroduction to Algorithms
Introduction to Algorithms 6.046J/18.401 Lecture 17 Prof. Piotr Indyk Computational Geometry ctd. Segment intersection problem: Given: a set of n distinct segments s 1 s n, represented by coordinates of
More informationLine segment intersection. Family of intersection problems
CG Lecture 2 Line segment intersection Intersecting two line segments Line sweep algorithm Convex polygon intersection Boolean operations on polygons Subdivision overlay algorithm 1 Family of intersection
More informationCS 532: 3D Computer Vision 11 th Set of Notes
1 CS 532: 3D Computer Vision 11 th Set of Notes Instructor: Philippos Mordohai Webpage: www.cs.stevens.edu/~mordohai E-mail: Philippos.Mordohai@stevens.edu Office: Lieb 215 Lecture Outline Line Intersection
More informationCMSC 754 Computational Geometry 1
CMSC 754 Computational Geometry 1 David M. Mount Department of Computer Science University of Maryland Fall 2005 1 Copyright, David M. Mount, 2005, Dept. of Computer Science, University of Maryland, College
More informationComputational Geometry
Lecture 1: Introduction and convex hulls Geometry: points, lines,... Geometric objects Geometric relations Combinatorial complexity Computational geometry Plane (two-dimensional), R 2 Space (three-dimensional),
More informationCS2223: Algorithms Sorting Algorithms, Heap Sort, Linear-time sort, Median and Order Statistics
CS2223: Algorithms Sorting Algorithms, Heap Sort, Linear-time sort, Median and Order Statistics 1 Sorting 1.1 Problem Statement You are given a sequence of n numbers < a 1, a 2,..., a n >. You need to
More information2 A Plane Sweep Algorithm for Line Segment Intersection
EECS 396/496: Computational Geometry Fall 2017 Lecturer: Huck Bennett Lecture 2: Line Segment Intersection In this lecture, we will study the problem of computing all intersections of a set of line segmentn
More informationCSE331 Introduction to Algorithms Lecture 15 Minimum Spanning Trees
CSE1 Introduction to Algorithms Lecture 1 Minimum Spanning Trees Antoine Vigneron antoine@unist.ac.kr Ulsan National Institute of Science and Technology July 11, 201 Antoine Vigneron (UNIST) CSE1 Lecture
More information1/60. Geometric Algorithms. Lecture 1: Introduction. Convex Hulls
1/60 Geometric Algorithms Lecture 1: Introduction Convex Hulls Geometric algorithms scope 2/60 Geometry algorithms (practice): Study of geometric problems that arise in various applications and how algorithms
More informationComputing intersections in a set of line segments: the Bentley-Ottmann algorithm
Computing intersections in a set of line segments: the Bentley-Ottmann algorithm Michiel Smid October 14, 2003 1 Introduction In these notes, we introduce a powerful technique for solving geometric problems.
More informationComputational Geometry
CS 5633 -- Spring 2004 Computational Geometry Carola Wenk Slides courtesy of Charles Leiserson with small changes by Carola Wenk CS 5633 Analysis of Algorithms 1 Computational geometry Algorithms for solving
More informationLinear Programming in Small Dimensions
Linear Programming in Small Dimensions Lekcija 7 sergio.cabello@fmf.uni-lj.si FMF Univerza v Ljubljani Edited from slides by Antoine Vigneron Outline linear programming, motivation and definition one dimensional
More informationCS 234. Module 8. November 15, CS 234 Module 8 ADT Priority Queue 1 / 22
CS 234 Module 8 November 15, 2018 CS 234 Module 8 ADT Priority Queue 1 / 22 ADT Priority Queue Data: (key, element pairs) where keys are orderable but not necessarily distinct, and elements are any data.
More informationCS 532: 3D Computer Vision 14 th Set of Notes
1 CS 532: 3D Computer Vision 14 th Set of Notes Instructor: Philippos Mordohai Webpage: www.cs.stevens.edu/~mordohai E-mail: Philippos.Mordohai@stevens.edu Office: Lieb 215 Lecture Outline Triangulating
More informationCSE 373 Winter 2009: Midterm #1 (closed book, closed notes, NO calculators allowed)
Name: Email address: CSE 373 Winter 2009: Midterm #1 (closed book, closed notes, NO calculators allowed) Instructions: Read the directions for each question carefully before answering. We may give partial
More informationAdvanced Algorithms Computational Geometry Prof. Karen Daniels. Fall, 2012
UMass Lowell Computer Science 91.504 Advanced Algorithms Computational Geometry Prof. Karen Daniels Fall, 2012 O Rourke Chapter 7 Search & Intersection Chapter 7 Search & Intersection Segment-Segment Intersection
More informationData Structures and Algorithms
Data Structures and Algorithms Spring 2017-2018 Outline 1 Priority Queues Outline Priority Queues 1 Priority Queues Jumping the Queue Priority Queues In normal queue, the mode of selection is first in,
More informationComputational Geometry Algorithmische Geometrie
Algorithmische Geometrie Panos Giannopoulos Wolfgang Mulzer Lena Schlipf AG TI SS 2013 !! Register in Campus Management!! Outline What you need to know (before taking this course) What is the course about?
More informationComputational Geometry. Lecture 17
Computational Geometry Lecture 17 Computational geometry Algorithms for solving geometric problems in 2D and higher. Fundamental objects: Basic structures: point line segment line point set polygon L17.2
More informationExternal-Memory Algorithms with Applications in GIS - (L. Arge) Enylton Machado Roberto Beauclair
External-Memory Algorithms with Applications in GIS - (L. Arge) Enylton Machado Roberto Beauclair {machado,tron}@visgraf.impa.br Theoretical Models Random Access Machine Memory: Infinite Array. Access
More informationFlavor of Computational Geometry. Voronoi Diagrams. Shireen Y. Elhabian Aly A. Farag University of Louisville
Flavor of Computational Geometry Voronoi Diagrams Shireen Y. Elhabian Aly A. Farag University of Louisville March 2010 Pepperoni Sparse Pizzas Olive Sparse Pizzas Just Two Pepperonis A person gets the
More informationUniversity of Waterloo CS240, Winter 2010 Assignment 2
University of Waterloo CS240, Winter 2010 Assignment 2 Due Date: Wednesday, February 10, at 5:00pm Please read http://www.student.cs.uwaterloo.ca/~cs240/w10/guidelines.pdf for guidelines on submission.
More informationOutline. Computer Science 331. Heap Shape. Binary Heaps. Heap Sort. Insertion Deletion. Mike Jacobson. HeapSort Priority Queues.
Outline Computer Science 33 Heap Sort Mike Jacobson Department of Computer Science University of Calgary Lectures #5- Definition Representation 3 5 References Mike Jacobson (University of Calgary) Computer
More informationCOMP Analysis of Algorithms & Data Structures
COMP 3170 - Analysis of Algorithms & Data Structures Shahin Kamali Lower Bounds CLRS 8.1 University of Manitoba COMP 3170 - Analysis of Algorithms & Data Structures 1 / 21 Lower Bounds Introductions Assume
More information5. DIVIDE AND CONQUER I
5. DIVIDE AND CONQUER I mergesort counting inversions closest pair of points randomized quicksort median and selection Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley Copyright 2013
More informationCourse Review for Finals. Cpt S 223 Fall 2008
Course Review for Finals Cpt S 223 Fall 2008 1 Course Overview Introduction to advanced data structures Algorithmic asymptotic analysis Programming data structures Program design based on performance i.e.,
More informationElementary maths for GMT. Algorithm analysis Part II
Elementary maths for GMT Algorithm analysis Part II Algorithms, Big-Oh and Big-Omega An algorithm has a O( ) and Ω( ) running time By default, we mean the worst case running time A worst case O running
More informationMore about The Competition
Data Structure I More about The Competition TLE? 10 8 integer operations, or 10 7 floating point operations, in a for loop, run in around one second for a typical desktop PC. Therefore, if n = 20, then
More informationCS 361 Data Structures & Algs Lecture 11. Prof. Tom Hayes University of New Mexico
CS 361 Data Structures & Algs Lecture 11 Prof. Tom Hayes University of New Mexico 09-28-2010 1 Last Time Priority Queues & Heaps Heapify (up and down) 1: Preserve shape of tree 2: Swaps restore heap order
More informationCS61BL. Lecture 5: Graphs Sorting
CS61BL Lecture 5: Graphs Sorting Graphs Graphs Edge Vertex Graphs (Undirected) Graphs (Directed) Graphs (Multigraph) Graphs (Acyclic) Graphs (Cyclic) Graphs (Connected) Graphs (Disconnected) Graphs (Unweighted)
More informationCMPS 3130/6130 Computational Geometry Spring Voronoi Diagrams. Carola Wenk. Based on: Computational Geometry: Algorithms and Applications
CMPS 3130/6130 Computational Geometry Spring 2015 Voronoi Diagrams Carola Wenk Based on: Computational Geometry: Algorithms and Applications 2/19/15 CMPS 3130/6130 Computational Geometry 1 Voronoi Diagram
More informationComputational Geometry TOPICS Preliminaries Point in a Polygon Polygon Construction Convex Hulls
Computational Geometry TOPICS Preliminaries Point in a Polygon Polygon Construction Convex Hulls CSE5311 Kumar 1 Geometric Algorithms Geometric Algorithms find applications in such areas as Computer Graphics
More informationLecture 13: AVL Trees and Binary Heaps
Data Structures Brett Bernstein Lecture 13: AVL Trees and Binary Heaps Review Exercises 1. ( ) Interview question: Given an array show how to shue it randomly so that any possible reordering is equally
More informationDesign and Analysis of Algorithms Lecture- 9: Binary Search Trees
Design and Analysis of Algorithms Lecture- 9: Binary Search Trees Dr. Chung- Wen Albert Tsao 1 Binary Search Trees Data structures that can support dynamic set operations. Search, Minimum, Maximum, Predecessor,
More informationBalanced Binary Search Trees. Victor Gao
Balanced Binary Search Trees Victor Gao OUTLINE Binary Heap Revisited BST Revisited Balanced Binary Search Trees Rotation Treap Splay Tree BINARY HEAP: REVIEW A binary heap is a complete binary tree such
More informationHow many leaves on the decision tree? There are n! leaves, because every permutation appears at least once.
Chapter 8. Sorting in Linear Time Types of Sort Algorithms The only operation that may be used to gain order information about a sequence is comparison of pairs of elements. Quick Sort -- comparison-based
More informationAlgorithm Design and Analysis
Algorithm Design and Analysis LECTURE 13 Divide and Conquer Closest Pair of Points Convex Hull Strassen Matrix Mult. Adam Smith 9/24/2008 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova,
More informationCS 410/584, Algorithm Design & Analysis, Lecture Notes 8!
CS 410/584, Algorithm Design & Analysis, Computational Geometry! Algorithms for manipulation of geometric objects We will concentrate on 2-D geometry Numerically robust try to avoid division Round-off
More informationHigh-Dimensional Computational Geometry. Jingbo Shang University of Illinois at Urbana-Champaign Mar 5, 2018
High-Dimensional Computational Geometry Jingbo Shang University of Illinois at Urbana-Champaign Mar 5, 2018 Outline 3-D vector geometry High-D hyperplane intersections Convex hull & its extension to 3
More informationNotes and Answers to Homework Exam 1, Geometric Algorithms, 2017
Notes and Answers to Homework Exam 1, Geometric Algorithms, 2017 Below are some notes and sketches of correct answers for the first homework exam. We have also included the most common mistakes that were
More informationLecture 1: September 6, 2001
Lecture 1: September 6, 2001 Welcome to 6.838J, Geometric Computation! Introductions Overview and Goals General Information Syllabus 2D Convex Hull Signup sheets (return by end of class) MIT 6.838J/4.214J
More informationProgramming II (CS300)
1 Programming II (CS300) Chapter 10: Search and Heaps MOUNA KACEM mouna@cs.wisc.edu Spring 2018 Search and Heaps 2 Linear Search Binary Search Introduction to trees Priority Queues Heaps Linear Search
More informationECE 242 Data Structures and Algorithms. Heaps I. Lecture 22. Prof. Eric Polizzi
ECE 242 Data Structures and Algorithms http://www.ecs.umass.edu/~polizzi/teaching/ece242/ Heaps I Lecture 22 Prof. Eric Polizzi Motivations Review of priority queue Input F E D B A Output Input Data structure
More informationAlgorithms, Spring 2014, CSE, OSU Lecture 2: Sorting
6331 - Algorithms, Spring 2014, CSE, OSU Lecture 2: Sorting Instructor: Anastasios Sidiropoulos January 10, 2014 Sorting Given an array of integers A[1... n], rearrange its elements so that A[1] A[2]...
More informationCSE 5311 Notes 13: Computational Geometry
CSE 5311 Notes 13: Computational Geometry (Last updated 4/17/17 4:39 PM) SMALLEST ENCLOSING DISK See section 4.7 of de Berg ( http://dx.doi.org.ezproxy.uta.edu/10.1007/978-3-540-77974-2 ) Algorithm MINIDISC(P)
More informationAnalyze the obvious algorithm, 5 points Here is the most obvious algorithm for this problem: (LastLargerElement[A[1..n]:
CSE 101 Homework 1 Background (Order and Recurrence Relations), correctness proofs, time analysis, and speeding up algorithms with restructuring, preprocessing and data structures. Due Thursday, April
More informationCSE 421 Greedy Alg: Union Find/Dijkstra s Alg
CSE 1 Greedy Alg: Union Find/Dijkstra s Alg Shayan Oveis Gharan 1 Dijkstra s Algorithm Dijkstra(G, c, s) { d s 0 foreach (v V) d[v] //This is the key of node v foreach (v V) insert v onto a priority queue
More informationLecture: Analysis of Algorithms (CS )
Lecture: Analysis of Algorithms (CS583-002) Amarda Shehu Fall 2017 Amarda Shehu Lecture: Analysis of Algorithms (CS583-002) Sorting in O(n lg n) Time: Heapsort 1 Outline of Today s Class Sorting in O(n
More information08 A: Sorting III. CS1102S: Data Structures and Algorithms. Martin Henz. March 10, Generated on Tuesday 9 th March, 2010, 09:58
08 A: Sorting III CS1102S: Data Structures and Algorithms Martin Henz March 10, 2010 Generated on Tuesday 9 th March, 2010, 09:58 CS1102S: Data Structures and Algorithms 08 A: Sorting III 1 1 Recap: Sorting
More information2. Instance simplification Solve a problem s instance by transforming it into another simpler/easier instance of the same problem
CmSc 20 Intro to Algorithms Chapter 6. Transform and Conquer Algorithms. Introduction This group of techniques solves a problem by a transformation to a simpler/more convenient instance of the same problem
More information07 B: Sorting II. CS1102S: Data Structures and Algorithms. Martin Henz. March 5, Generated on Friday 5 th March, 2010, 08:31
Recap: Sorting 07 B: Sorting II CS1102S: Data Structures and Algorithms Martin Henz March 5, 2010 Generated on Friday 5 th March, 2010, 08:31 CS1102S: Data Structures and Algorithms 07 B: Sorting II 1
More informationCS350: Data Structures Heaps and Priority Queues
Heaps and Priority Queues James Moscola Department of Engineering & Computer Science York College of Pennsylvania James Moscola Priority Queue An abstract data type of a queue that associates a priority
More informationOrthogonal line segment intersection. Computational Geometry [csci 3250] Laura Toma Bowdoin College
Orthogonal line segment intersection Computational Geometry [csci 3250] Laura Toma Bowdoin College Line segment intersection The problem (what) Applications (why) Algorithms (how) A special case: Orthogonal
More informationDIT960 Datastrukturer
DIT90 Datastrukturer suggested solutions for exam 07-0-0. The following code takes as input two arrays with elements of the same type. The arrays are called a and b. The code returns a dynamic array which
More informationCSE 214 Computer Science II Heaps and Priority Queues
CSE 214 Computer Science II Heaps and Priority Queues Spring 2018 Stony Brook University Instructor: Shebuti Rayana shebuti.rayana@stonybrook.edu http://www3.cs.stonybrook.edu/~cse214/sec02/ Introduction
More informationHeaps. Heapsort. [Reading: CLRS 6] Laura Toma, csci2000, Bowdoin College
Heaps. Heapsort. [Reading: CLRS 6] Laura Toma, csci000, Bowdoin College So far we have discussed tools necessary for analysis of algorithms (growth, summations and recurrences) and we have seen a couple
More informationBasic Data Structures (Version 7) Name:
Prerequisite Concepts for Analysis of Algorithms Basic Data Structures (Version 7) Name: Email: Concept: mathematics notation 1. log 2 n is: Code: 21481 (A) o(log 10 n) (B) ω(log 10 n) (C) Θ(log 10 n)
More informationCS 410/584, Algorithm Design & Analysis, Lecture Notes 8
CS 410/584,, Computational Geometry Algorithms for manipulation of geometric objects We will concentrate on 2-D geometry Numerically robust try to avoid division Round-off error Divide-by-0 checks Techniques
More informationComputational Geometry
Motivation Motivation Polygons and visibility Visibility in polygons Triangulation Proof of the Art gallery theorem Two points in a simple polygon can see each other if their connecting line segment is
More informationComputer Science Spring 2005 Final Examination, May 12, 2005
Computer Science 302 00 Spring 2005 Final Examination, May 2, 2005 Name: No books, notes, or scratch paper. Use pen or pencil, any color. Use the backs of the pages for scratch paper. If you need more
More informationPriority queues. Priority queues. Priority queue operations
Priority queues March 30, 018 1 Priority queues The ADT priority queue stores arbitrary objects with priorities. An object with the highest priority gets served first. Objects with priorities are defined
More informationPriority Queues. T. M. Murali. January 23, T. M. Murali January 23, 2008 Priority Queues
Priority Queues T. M. Murali January 23, 2008 Motivation: Sort a List of Numbers Sort INSTANCE: Nonempty list x 1, x 2,..., x n of integers. SOLUTION: A permutation y 1, y 2,..., y n of x 1, x 2,..., x
More informationCSE 332, Spring 2010, Midterm Examination 30 April 2010
CSE 332, Spring 2010, Midterm Examination 30 April 2010 Please do not turn the page until the bell rings. Rules: The exam is closed-book, closed-note. You may use a calculator for basic arithmetic only.
More informationCS221: Algorithms and Data Structures. Sorting Takes Priority. Steve Wolfman (minor tweaks by Alan Hu)
CS221: Algorithms and Data Structures Sorting Takes Priority Steve Wolfman (minor tweaks by Alan Hu) 1 Today s Outline Sorting with Priority Queues, Three Ways 2 How Do We Sort with a Priority Queue? You
More informationPriority Queues. T. M. Murali. January 29, 2009
Priority Queues T. M. Murali January 29, 2009 Motivation: Sort a List of Numbers Sort INSTANCE: Nonempty list x 1, x 2,..., x n of integers. SOLUTION: A permutation y 1, y 2,..., y n of x 1, x 2,..., x
More informationRandomized incremental construction. Trapezoidal decomposition: Special sampling idea: Sample all except one item
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
More information26 The closest pair problem
The closest pair problem 1 26 The closest pair problem Sweep algorithms solve many kinds of proximity problems efficiently. We present a simple sweep that solves the two-dimensional closest pair problem
More informationCS 361 Data Structures & Algs Lecture 9. Prof. Tom Hayes University of New Mexico
CS 361 Data Structures & Algs Lecture 9 Prof. Tom Hayes University of New Mexico 09-21-2010 1 Today Orderings Searching Sorting Priority Queues & Heaps 2 Order Relation We say a binary relation R is an
More informationUnit Outline. Comparing Sorting Algorithms Heapsort Mergesort Quicksort More Comparisons Complexity of Sorting 2 / 33
Unit #4: Sorting CPSC : Basic Algorithms and Data Structures Anthony Estey, Ed Knorr, and Mehrdad Oveisi 0W Unit Outline Comparing Sorting Algorithms Heapsort Mergesort Quicksort More Comparisons Complexity
More informationLine segment intersection (I): Orthogonal line segment intersection. Computational Geometry [csci 3250] Laura Toma Bowdoin College
Line segment intersection (I): Orthogonal line segment intersection Computational Geometry [csci 3250] Laura Toma Bowdoin College Outline The problem (what) Applications (why) Algorithms (how) A special
More informationInstructions. Definitions. Name: CMSC 341 Fall Question Points I. /12 II. /30 III. /10 IV. /12 V. /12 VI. /12 VII.
CMSC 341 Fall 2013 Data Structures Final Exam B Name: Question Points I. /12 II. /30 III. /10 IV. /12 V. /12 VI. /12 VII. /12 TOTAL: /100 Instructions 1. This is a closed-book, closed-notes exam. 2. You
More informationCITS3001. Algorithms, Agents and Artificial Intelligence. Semester 2, 2016
CITS3001 Algorithms, Agents and Artificial Intelligence Semester 2, 2016 Tim French School of Computer Science & Software Eng. The University of Western Australia 2. Review of algorithmic concepts CLRS,
More informationPseudo code of algorithms are to be read by.
Cs502 Quiz No1 Complete Solved File Pseudo code of algorithms are to be read by. People RAM Computer Compiler Approach of solving geometric problems by sweeping a line across the plane is called sweep.
More informationGeometric Algorithms. 1. Objects
Geometric Algorithms 1. Definitions 2. Line-Segment properties 3. Inner Points of polygons 4. Simple polygons 5. Convex hulls 6. Closest pair of points 7. Diameter of a point set 1. Objects 2-dimensional
More informationProblem. Input: An array A = (A[1],..., A[n]) with length n. Output: a permutation A of A, that is sorted: A [i] A [j] for all. 1 i j n.
Problem 5. Sorting Simple Sorting, Quicksort, Mergesort Input: An array A = (A[1],..., A[n]) with length n. Output: a permutation A of A, that is sorted: A [i] A [j] for all 1 i j n. 98 99 Selection Sort
More informationRed-Black-Trees and Heaps in Timestamp-Adjusting Sweepline Based Algorithms
Department of Informatics, University of Zürich Vertiefungsarbeit Red-Black-Trees and Heaps in Timestamp-Adjusting Sweepline Based Algorithms Mirko Richter Matrikelnummer: 12-917-175 Email: mirko.richter@uzh.ch
More informationLecture 7: Computational Geometry
Lecture 7: Computational Geometry CS 491 CAP Uttam Thakore Friday, October 7 th, 2016 Credit for many of the slides on solving geometry problems goes to the Stanford CS 97SI course lecture on computational
More informationApproximating a set of points by circles
Approximating a set of points by circles Sandra Gesing June 2005 Abstract This paper is an abstract of the German diploma thesis Approximation von Punktmengen durch Kreise finished by the author in March
More informationComputer Science 302 Spring 2007 Practice Final Examination: Part I
Computer Science 302 Spring 2007 Practice Final Examination: Part I Name: This practice examination is much longer than the real final examination will be. If you can work all the problems here, you will
More informationHEAPS: IMPLEMENTING EFFICIENT PRIORITY QUEUES
HEAPS: IMPLEMENTING EFFICIENT PRIORITY QUEUES 2 5 6 9 7 Presentation for use with the textbook Data Structures and Algorithms in Java, 6 th edition, by M. T. Goodrich, R. Tamassia, and M. H., Wiley, 2014
More informationChapter 5 Data Structures Algorithm Theory WS 2016/17 Fabian Kuhn
Chapter 5 Data Structures Algorithm Theory WS 06/ Fabian Kuhn Examples Dictionary: Operations: insert(key,value), delete(key), find(key) Implementations: Linked list: all operations take O(n) time (n:
More informationCSE373: Data Structures & Algorithms Lecture 17: Minimum Spanning Trees. Dan Grossman Fall 2013
CSE373: Data Structures & Algorithms Lecture 7: Minimum Spanning Trees Dan Grossman Fall 03 Spanning Trees A simple problem: Given a connected undirected graph G=(V,E), find a minimal subset of edges such
More informationSorting and Searching
Sorting and Searching Lecture 2: Priority Queues, Heaps, and Heapsort Lecture 2: Priority Queues, Heaps, and Heapsort Sorting and Searching 1 / 24 Priority Queue: Motivating Example 3 jobs have been submitted
More informationCSC Design and Analysis of Algorithms. Lecture 8. Transform and Conquer II Algorithm Design Technique. Transform and Conquer
CSC 301- Design and Analysis of Algorithms Lecture Transform and Conquer II Algorithm Design Technique Transform and Conquer This group of techniques solves a problem by a transformation to a simpler/more
More information1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1
Asymptotics, Recurrence and Basic Algorithms 1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1 1. O(logn) 2. O(n) 3. O(nlogn) 4. O(n 2 ) 5. O(2 n ) 2. [1 pt] What is the solution
More informationLecture 7. Transform-and-Conquer
Lecture 7 Transform-and-Conquer 6-1 Transform and Conquer This group of techniques solves a problem by a transformation to a simpler/more convenient instance of the same problem (instance simplification)
More informationPriority Queues. T. M. Murali. January 26, T. M. Murali January 26, 2016 Priority Queues
Priority Queues T. M. Murali January 26, 2016 Motivation: Sort a List of Numbers Sort INSTANCE: Nonempty list x 1, x 2,..., x n of integers. SOLUTION: A permutation y 1, y 2,..., y n of x 1, x 2,..., x
More informationBinary heaps (chapters ) Leftist heaps
Binary heaps (chapters 20.3 20.5) Leftist heaps Binary heaps are arrays! A binary heap is really implemented using an array! 8 18 29 20 28 39 66 Possible because of completeness property 37 26 76 32 74
More informationCS 506, Sect 002 Homework 5 Dr. David Nassimi Foundations of CS Due: Week 11, Mon. Apr. 7 Spring 2014
CS 506, Sect 002 Homework 5 Dr. David Nassimi Foundations of CS Due: Week 11, Mon. Apr. 7 Spring 2014 Study: Chapter 4 Analysis of Algorithms, Recursive Algorithms, and Recurrence Equations 1. Prove the
More informationCourse Review. Cpt S 223 Fall 2009
Course Review Cpt S 223 Fall 2009 1 Final Exam When: Tuesday (12/15) 8-10am Where: in class Closed book, closed notes Comprehensive Material for preparation: Lecture slides & class notes Homeworks & program
More informationPriority Queues and Heaps
Priority Queues and Heaps Data Structures and Algorithms CSE 373 SU 18 BEN JONES 1 Warm Up We have seen several data structures that can implement the Dictionary ADT so far: Arrays, Binary (AVL) Trees,
More informationHeaps Outline and Required Reading: Heaps ( 7.3) COSC 2011, Fall 2003, Section A Instructor: N. Vlajic
1 Heaps Outline and Required Reading: Heaps (.3) COSC 2011, Fall 2003, Section A Instructor: N. Vlajic Heap ADT 2 Heap binary tree (T) that stores a collection of keys at its internal nodes and satisfies
More informationPrelim 2 Solution. CS 2110, November 19, 2015, 5:30 PM Total. Sorting Invariants Max Score Grader
Prelim 2 CS 2110, November 19, 2015, 5:30 PM 1 2 3 4 5 6 Total Question True Short Complexity Searching Trees Graphs False Answer Sorting Invariants Max 20 15 13 14 17 21 100 Score Grader The exam is closed
More informationComputer Science 210 Data Structures Siena College Fall Topic Notes: Priority Queues and Heaps
Computer Science 0 Data Structures Siena College Fall 08 Topic Notes: Priority Queues and Heaps Heaps and Priority Queues From here, we will look at some ways that trees are used in other structures. First,
More informationl Heaps very popular abstract data structure, where each object has a key value (the priority), and the operations are:
DDS-Heaps 1 Heaps - basics l Heaps very popular abstract data structure, where each object has a key value (the priority), and the operations are: l insert an object, find the object of minimum key (find
More informationCOMP Analysis of Algorithms & Data Structures
COMP 3170 - Analysis of Algorithms & Data Structures Shahin Kamali Binary Search Trees CLRS 12.2, 12.3, 13.2, read problem 13-3 University of Manitoba COMP 3170 - Analysis of Algorithms & Data Structures
More informationConnected Components of Underlying Graphs of Halving Lines
arxiv:1304.5658v1 [math.co] 20 Apr 2013 Connected Components of Underlying Graphs of Halving Lines Tanya Khovanova MIT November 5, 2018 Abstract Dai Yang MIT In this paper we discuss the connected components
More informationmanaging an evolving set of connected components implementing a Union-Find data structure implementing Kruskal s algorithm
Spanning Trees 1 Spanning Trees the minimum spanning tree problem three greedy algorithms analysis of the algorithms 2 The Union-Find Data Structure managing an evolving set of connected components implementing
More information