Divide and conquer algorithms. March 12, 2018 CSCI211 - Sprenkle. What is a recurrence rela&on? How can you compute D&C running &mes?

Size: px
Start display at page:

Download "Divide and conquer algorithms. March 12, 2018 CSCI211 - Sprenkle. What is a recurrence rela&on? How can you compute D&C running &mes?"

Transcription

1 Objec&ves Divide and conquer algorithms Ø Coun&ng inversions Ø Closest pairs of points March 1, 018 CSCI11 - Sprenkle 1 Review What is a recurrence rela&on? How can you compute D&C running &mes? March 1, 018 CSCI11 - Sprenkle 1

2 Coun&ng Inversions: Divide-and-Conquer Towards a solu+on Assume number represents where item should be in the list, i.e., where it is in someone else s list Should be at position 5 What was the approach so far? March 1, 018 CSCI11 - Sprenkle Coun&ng Inversions: Divide-and-Conquer Divide: separate list into two pieces Conquer: recursively count inversions in each half Combine: count inversions where a i and a j are in different halves, and return sum of three quan&&es Divide: O(1) blue-blue inversions 8 green-green inversions 9 blue-green inversions 5-, 4-, 8-, 8-, 8-7, 10-, 10-9, 10-, 10-7 Total = = Conquer: T(n / ) Combine: Θ(n ) What would make figuring out blue-green inversions easier? March 1, 018 CSCI11 - Sprenkle 4

3 Coun&ng Inversions: Combine Combine: count blue-green inversions Ø Assume each half is sorted Ø Count inversions Ø Merge into sorted whole to maintain sorted invariant What does sorting do for us? What is our algorithm for counting the inversions and merging? Note: these lists are only subsets of the original list March 1, 018 CSCI11 - Sprenkle 5 Coun&ng Inversions: Combine Combine: count blue-green inversions Ø Assume each half is sorted Ø Count inversions Ø Merge into sorted whole to maintain sorted invariant Count: O(n) 1 blue-green inversions: Merge: O(n) We ll run through an example in a bit March 1, 018 CSCI11 - Sprenkle

4 Merge-and-Count(A,B): i=0 j=0 inversions = 0 output = [] while i < A.size and j < B.size: output.append( min(a[i], B[j]) ) if B[j] < A[i]: inversions += A.size i update i or j Append the remainder of the non-exhausted list to the output return inversions and output March 1, 018 CSCI11 - Sprenkle 7 Precondition: A and B are sorted Merge-and-Count(A,B): i=0 (front of list A) j=0 (front of list B) inversions = 0 output = [] while A not empty and B not empty: output.append( min(a[i], B[j]) ) if B[j] < A[i]: inversions += A.size i (remaining elements in A) update i or j (whichever had smaller element) Append the remainder of the non-exhausted list to the output return inversions and output March 1, 018 CSCI11 - Sprenkle 8 4

5 Step Given, A B Total: March 1, 018 CSCI11 - Sprenkle 9 Given, Total: March 1, 018 CSCI11 - Sprenkle 10 5

6 Given, Total: March 1, 018 CSCI11 - Sprenkle 11 Given, Total: March 1, 018 CSCI11 - Sprenkle 1

7 Given, Total: March 1, 018 CSCI11 - Sprenkle 1 Given, Total: March 1, 018 CSCI11 - Sprenkle 14 7

8 Given, Total: March 1, 018 CSCI11 - Sprenkle 15 Given, Total: March 1, 018 CSCI11 - Sprenkle 1 8

9 Given, Total: March 1, 018 CSCI11 - Sprenkle 17 Given, Total: + March 1, 018 CSCI11 - Sprenkle 18 9

10 Given, Total: + March 1, 018 CSCI11 - Sprenkle 19 Given, Total: + March 1, 018 CSCI11 - Sprenkle 0 10

11 Given, Total: + March 1, 018 CSCI11 - Sprenkle 1 Given, Total: + + March 1, 018 CSCI11 - Sprenkle 11

12 Given, Total: + + March 1, 018 CSCI11 - Sprenkle Given, Total: March 1, 018 CSCI11 - Sprenkle 4 1

13 Given, Total: March 1, 018 CSCI11 - Sprenkle 5 Given, Total: March 1, 018 CSCI11 - Sprenkle 1

14 Given, Total: March 1, 018 CSCI11 - Sprenkle 7 Given, Total: March 1, 018 CSCI11 - Sprenkle 8 14

15 Given, first half exhausted Total: March 1, 018 CSCI11 - Sprenkle 9 Given, Total: March 1, 018 CSCI11 - Sprenkle 0 15

16 Given, Total: March 1, 018 CSCI11 - Sprenkle 1 Given, i = Total: March 1, 018 CSCI11 - Sprenkle 1

17 Given, Total: = 1 March 1, 018 CSCI11 - Sprenkle Coun&ng Inversions: Implementa&on Sort-and-Count(L) if list L has one element return 0 and the list L Divide the list into two halves A and B (i A, A) = Sort-and-Count(A) (i B, B) = Sort-and-Count(B) (i, L) = Merge-and-Count(A, B) total_inversions = i A + i B + i return total_inversions and the sorted list L March 1, 018 CSCI11 - Sprenkle 4 17

18 Coun&ng Inversions: Implementa&on Sort-and-Count(L) if list L has one element return 0 and the list L Divide the list into two halves A and B (i A, A) = Sort-and-Count(A) (i B, B) = Sort-and-Count(B) (i, L) = Merge-and-Count(A, B) total_inversions = i A + i B + i return total_inversions and the sorted list L Merge-and-Count Ø Pre-condi&on. A and B are sorted. Ø Post-condi&on. L is sorted. March 1, 018 CSCI11 - Sprenkle 5 Coun&ng Inversions: Implementa&on Sort-and-Count(L) if list L has one element return 0 and the list L Divide the list into two halves A and B (i A, A) = Sort-and-Count(A) (i B, B) = Sort-and-Count(B) (i, L) = Merge-and-Count(A, B) total_inversions = i A + i B + i return total_inversions and the sorted list L Merge-and-Count Ø Pre-condi&on. A and B are sorted. Ø Post-condi&on. L is sorted. Recurrence relation? Runtime of algorithm? March 1, 018 CSCI11 - Sprenkle 18

19 Analysis Recurrence Rela&on: T(n) T(n/) + T(n/) + O(n) èt(n) O(n log n) Sort-and-Count(L) if list L has one element return 0 and the list L Divide the list into two halves A and B (i A, A) = Sort-and-Count(A) T(n/) (i B, B) = Sort-and-Count(B) T(n/) (i, L) = Merge-and-Count(A, B) O(n) total_inversions = i A + i B + i return total_inversions and the sorted list L March 1, 018 CSCI11 - Sprenkle 7 CLOSEST PAIR OF POINTS March 1, 018 CSCI11 - Sprenkle 8 19

20 Computa&onal Geometry Algorithms and data structures for geometrical objects Ø Points, line segments, polygons, etc. Ø Common mo&vator: large data sets à efficiency Some Applica&ons Ø Graphics Ø Robo&cs mo&on planning and visibility problems Ø Geographic informa&on systems (GIS) geometrical loca&on and search, route planning March 1, 018 CSCI11 - Sprenkle 9 Closest Pair of Points Closest pair. Given n points in the plane, find a pair with smallest Euclidean distance between them. Ø Special case of nearest neighbor, Euclidean MST, Voronoi. Brute force? fast closest pair inspired fast algorithms for these problems March 1, 018 CSCI11 - Sprenkle 40 0

21 Closest Pair of Points Closest pair. Given n points in the plane, find a pair with smallest Euclidean distance between them. Ø Special case of nearest neighbor, Euclidean MST, Voronoi. Brute force. Check all pairs of points p and q with Θ(n ) comparisons March 1, 018 CSCI11 - Sprenkle 41 Simplify: All Points on a Line How could we solve this problem? What is its running &me? March 1, 018 CSCI11 - Sprenkle 4 1

22 Simplify: All Points on a Line How could we solve this problem? Ø Sort the points Monotonically increasing x/y coordinates No closer points than neighbors in sorted list Ø Step through, looking at the distances between each pair What is its running &me? Ø O(n logn) Why won t this work for D? March 1, 018 CSCI11 - Sprenkle 4 Closest Pair of Points Closest pair. Given n points in the plane, find a pair with smallest Euclidean distance between them. Ø Special case of nearest neighbor, Euclidean MST, Voronoi. Brute force. Check all pairs of points p and q with Θ(n ) comparisons 1-D version. O(n log n) Ø Easy if points are on a line Assump&on. No two points have same x coordinate to make presenta&on cleaner March 1, 018 CSCI11 - Sprenkle 44

23 Closest Pair of Points: First Aiempt Divide. Sub-divide region into 4 quadrants L Why does this seem to be a natural first step? Any problems with implementing this approach? March 1, 018 CSCI11 - Sprenkle 45 Closest Pair of Points: First Aiempt Divide. Sub-divide region into 4 quadrants Obstacle. Impossible to ensure n/4 points in each piece L March 1, 018 CSCI11 - Sprenkle 4

24 Closest Pair of Points Divide: draw ver&cal line L so that roughly ½n points on each side How do we implement this? L March 1, 018 CSCI11 - Sprenkle 47 Closest Pair of Points Divide: draw ver&cal line L so that roughly ½n points on each side Conquer: find closest pair in each side recursively L 1 1 March 1, 018 CSCI11 - Sprenkle 48 4

25 Closest Pair of Points Divide: draw ver&cal line L so that roughly ½n points on each side Conquer: find closest pair in each side recursively Combine: find closest pair with one point in each side Return best of solu&ons seems like Θ(n ) Do we need to check all pairs? L March 1, 018 CSCI11 - Sprenkle 49 Closest Pair of Points Find closest pair with one point in each side, assuming that distance < δ where δ = min(lel_min_dist, right_min_dist) L 1 1 δ = min(1, 1) March 1, 018 CSCI11 - Sprenkle 50 5

26 Closest Pair of Points Find closest pair with one point in each side, assuming that distance < δ. Ø Observa&on: only need to consider points within δ of line L. δ L 1 1 δ = min(1, 1) March 1, 018 CSCI11 - Sprenkle 51 Closest Pair of Points Find closest pair w/ 1 point in each side, assuming that distance < δ. Ø Observa&on: only consider points within δ of line L Ø Sort points in δ-strip by their y coordinate How many points are within that region? 7 L δ = min(1, 1) 1 March 1, 018 CSCI11 - Sprenkle δ 5

27 Closest Pair of Points Find closest pair w/ 1 point in each side, assuming that distance < δ Ø Observa&on: only consider points within δ of line L Ø Sort points in δ-strip by their y coordinate Only checks distances of those within 11 posi&ons in sorted list! 7 L δ = min(1, 1) 1 March 1, 018 CSCI11 - Sprenkle 5 δ Analyzing Cost of Combining Prepare minds to be blown Def. Let s i be the point in the δ-strip, with the i th smallest y- coordinate Claim. If i j 1, then the distance between s i and s j is at least δ Ø What is the distance of the box? Ø How many points can be in a box? Ø When do we know that points are > δ apart? i j ½δ ½δ ½δ March 1, 018 CSCI11 - Sprenkle δ δ 54 7

28 Looking Ahead Wiki: 4.8, PS 7 due Friday Exam handed out on Friday Ø Greedy and D&C Ø Due following Friday March 1, 018 CSCI11 - Sprenkle 55 8

5.4 Closest Pair of Points

5.4 Closest Pair of Points 5.4 Closest Pair of Points Closest pair. Given n points in the plane, find a pair with smallest Euclidean distance between them. Fundamental geometric primitive. Graphics, computer vision, geographic information

More information

Divide and Conquer 1

Divide and Conquer 1 Divide and Conquer A Useful Recurrence Relation Def. T(n) = number of comparisons to mergesort an input of size n. Mergesort recurrence. T(n) if n T n/2 T n/2 solve left half solve right half merging n

More information

Ch5. Divide-and-Conquer

Ch5. Divide-and-Conquer Ch5. Divide-and-Conquer 1 5.1 Mergesort Sorting Sorting. Given n elements, rearrange in ascending order. Applications. Sort a list of names. Organize an MP3 library. obvious applications Display Google

More information

Plan for Today. Finish recurrences. Inversion Counting. Closest Pair of Points

Plan for Today. Finish recurrences. Inversion Counting. Closest Pair of Points Plan for Today Finish recurrences Inversion Counting Closest Pair of Points Divide and Conquer Divide-and-conquer. Divide problem into several parts. Solve each part recursively. Combine solutions to sub-problems

More information

5. DIVIDE AND CONQUER I

5. 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 information

Algorithm Design and Analysis

Algorithm 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 information

Closest Pair of Points. Cormen et.al 33.4

Closest Pair of Points. Cormen et.al 33.4 Closest Pair of Points Cormen et.al 33.4 Closest Pair of Points Closest pair. Given n points in the plane, find a pair with smallest Euclidean distance between them. Fundamental geometric problem. Graphics,

More information

Divide-and-Conquer. Combine solutions to sub-problems into overall solution. Break up problem of size n into two equal parts of size!n.

Divide-and-Conquer. Combine solutions to sub-problems into overall solution. Break up problem of size n into two equal parts of size!n. Chapter 5 Divide and Conquer Slides by Kevin Wayne. Copyright 25 Pearson-Addon Wesley. All rights reserved. Divide-and-Conquer Divide-and-conquer. Break up problem into several parts. Solve each part recursively.

More information

Divide-Conquer-Glue Algorithms

Divide-Conquer-Glue Algorithms Divide-Conquer-Glue Algorithms Closest Pair Tyler Moore CSE 3353, SMU, Dallas, TX Lecture 12 5. DIVIDE AND CONQUER mergesort counting inversions closest pair of points randomized quicksort median and selection

More information

Chapter 5. Divide and Conquer. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Chapter 5. Divide and Conquer. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. Chapter 5 Divide and Conquer Slides by Kevin Wayne. Copyright 25 Pearson-Addison Wesley. All rights reserved. Divide-and-Conquer Divide-and-conquer. Break up problem into several parts. Solve each part

More information

CSE 202 Divide-and-conquer algorithms. Fan Chung Graham UC San Diego

CSE 202 Divide-and-conquer algorithms. Fan Chung Graham UC San Diego CSE 22 Divide-and-conquer algorithms Fan Chung Graham UC San Diego Announcements Homework due today before the class. About homework, write your own homework, allowing oral discussion with one fixed partner.

More information

CSE 202 Divide-and-conquer algorithms. Fan Chung Graham UC San Diego

CSE 202 Divide-and-conquer algorithms. Fan Chung Graham UC San Diego CSE 22 Divide-and-conquer algorithms Fan Chung Graham UC San Diego A useful fact about trees Any tree on n vertices contains a vertex v whose removal separates the remaining graph into two parts, one of

More information

Review implementation of Stable Matching Survey of common running times. Turn in completed problem sets. Jan 18, 2019 Sprenkle - CSCI211

Review implementation of Stable Matching Survey of common running times. Turn in completed problem sets. Jan 18, 2019 Sprenkle - CSCI211 Objectives Review implementation of Stable Matching Survey of common running times Turn in completed problem sets Jan 18, 2019 Sprenkle - CSCI211 1 Review: Asymptotic Analysis of Gale-Shapley Alg Not explicitly

More information

Closest Pair of Points in the Plane. Closest pair of points. Closest Pair of Points. Closest Pair of Points

Closest Pair of Points in the Plane. Closest pair of points. Closest Pair of Points. Closest Pair of Points Closest Pair of Points Closest pair of points. Given n points in the plane, find a pair with smallest euclidean distance between them. Closest Pair of Points in the Plane Inge i Gørtz The slides on the

More information

CSE 421 Closest Pair of Points, Master Theorem, Integer Multiplication

CSE 421 Closest Pair of Points, Master Theorem, Integer Multiplication CSE 421 Closest Pair of Points, Master Theorem, Integer Multiplication Shayan Oveis Gharan 1 Finding the Closest Pair of Points Closest Pair of Points (non geometric) Given n points and arbitrary distances

More information

Lecture 4 CS781 February 3, 2011

Lecture 4 CS781 February 3, 2011 Lecture 4 CS78 February 3, 2 Topics: Data Compression-Huffman Trees Divide-and-Conquer Solving Recurrence Relations Counting Inversions Closest Pair Integer Multiplication Matrix Multiplication Data Compression

More information

CSE 421 Algorithms: Divide and Conquer

CSE 421 Algorithms: Divide and Conquer CSE 42 Algorithms: Divide and Conquer Larry Ruzzo Thanks to Paul Beame, Kevin Wayne for some slides Outline: General Idea algorithm design paradigms: divide and conquer Review of Merge Sort Why does it

More information

Union Find. Data Structures and Algorithms Andrei Bulatov

Union Find. Data Structures and Algorithms Andrei Bulatov Union Find Data Structures and Algorithms Andrei Bulatov Algorithms Union Find 6-2 Union Find In a nutshell, Kruskal s algorithm starts with a completely disjoint graph, and adds edges creating a graph

More information

Union Find 11/2/2009. Union Find. Union Find via Linked Lists. Union Find via Linked Lists (cntd) Weighted-Union Heuristic. Weighted-Union Heuristic

Union Find 11/2/2009. Union Find. Union Find via Linked Lists. Union Find via Linked Lists (cntd) Weighted-Union Heuristic. Weighted-Union Heuristic Algorithms Union Find 16- Union Find Union Find Data Structures and Algorithms Andrei Bulatov In a nutshell, Kruskal s algorithm starts with a completely disjoint graph, and adds edges creating a graph

More information

Divide and Conquer. Design and Analysis of Algorithms Andrei Bulatov

Divide and Conquer. Design and Analysis of Algorithms Andrei Bulatov Divide and Conquer Design and Analysis of Algorithms Andrei Bulatov Algorithms Divide and Conquer 4-2 Divide and Conquer, MergeSort Recursive algorithms: Call themselves on subproblem Divide and Conquer

More information

CSE 421 Greedy Alg: Union Find/Dijkstra s Alg

CSE 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 information

Advanced Algorithms. Problem solving Techniques. Divide and Conquer הפרד ומשול

Advanced Algorithms. Problem solving Techniques. Divide and Conquer הפרד ומשול Advanced Algorithms Problem solving Techniques. Divide and Conquer הפרד ומשול 1 Divide and Conquer A method of designing algorithms that (informally) proceeds as follows: Given an instance of the problem

More information

Algorithms: Lecture 7. Chalmers University of Technology

Algorithms: Lecture 7. Chalmers University of Technology Algorithms: Lecture 7 Chalmers University of Technology Today s Lecture Divide & Conquer Counting Inversions Closest Pair of Points Multiplication of large integers Intro to the forthcoming problems Graphs:

More information

Divide-and-Conquer Algorithms

Divide-and-Conquer Algorithms Divide-and-Conquer Algorithms Divide and Conquer Three main steps Break input into several parts, Solve the problem in each part recursively, and Combine the solutions for the parts Contribution Applicable

More information

Objec&ves. Wrap up: Implemen&ng BFS and DFS Graph Applica&on: Bipar&te Graphs. Get out your BFS implementa&on handouts. Feb 2, 2018 CSCI211 - Sprenkle

Objec&ves. Wrap up: Implemen&ng BFS and DFS Graph Applica&on: Bipar&te Graphs. Get out your BFS implementa&on handouts. Feb 2, 2018 CSCI211 - Sprenkle Objec&ves Wrap up: Implemen&ng BFS and DFS Graph Applica&on: Bipar&te Graphs Get out your BFS implementa&on handouts Feb 2, 2018 CSCI211 - Sprenkle 1 Review What are two ways to find a connected component?

More information

Divide and Conquer. Algorithm Fall Semester

Divide and Conquer. Algorithm Fall Semester Divide and Conquer Algorithm 2014 Fall Semester Divide-and-Conquer The most-well known algorithm design strategy: 1. Divide instance of problem into two or more smaller instances 2. Solve smaller instances

More information

We can use a max-heap to sort data.

We can use a max-heap to sort data. Sorting 7B N log N Sorts 1 Heap Sort We can use a max-heap to sort data. Convert an array to a max-heap. Remove the root from the heap and store it in its proper position in the same array. Repeat until

More information

Chapter 1 Divide and Conquer Algorithm Theory WS 2015/16 Fabian Kuhn

Chapter 1 Divide and Conquer Algorithm Theory WS 2015/16 Fabian Kuhn Chapter 1 Divide and Conquer Algorithm Theory WS 2015/16 Fabian Kuhn Divide And Conquer Principle Important algorithm design method Examples from Informatik 2: Sorting: Mergesort, Quicksort Binary search

More information

CMSC 451: Divide and Conquer

CMSC 451: Divide and Conquer CMSC 451: Divide and Conquer Slides By: Carl Kingsford Department of Computer Science University of Maryland, College Park Based on Sections 5.1 5.3 of Algorithm Design by Kleinberg & Tardos. Greedy Recap

More information

Computational Geometry

Computational 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 information

CSC Design and Analysis of Algorithms. Lecture 6. Divide and Conquer Algorithm Design Technique. Divide-and-Conquer

CSC Design and Analysis of Algorithms. Lecture 6. Divide and Conquer Algorithm Design Technique. Divide-and-Conquer CSC 8301- Design and Analysis of Algorithms Lecture 6 Divide and Conquer Algorithm Design Technique Divide-and-Conquer The most-well known algorithm design strategy: 1. Divide a problem instance into two

More information

Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute

Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute Module 07 Lecture - 38 Divide and Conquer: Closest Pair of Points We now look at another divide and conquer algorithm,

More information

1 Closest Pair Problem

1 Closest Pair Problem 1 Closest Pair Problem Computational Geometry, Lectures 3,4 Closest Pair Problem Scribe Varun Nayyar Given a set of n points determine points a,b such that the interpoint distance ( Euclidean ) is the

More information

Chapter 1 Divide and Conquer Algorithm Theory WS 2014/15 Fabian Kuhn

Chapter 1 Divide and Conquer Algorithm Theory WS 2014/15 Fabian Kuhn Chapter 1 Divide and Conquer Algorithm Theory WS 2014/15 Fabian Kuhn Divide And Conquer Principle Important algorithm design method Examples from Informatik 2: Sorting: Mergesort, Quicksort Binary search

More information

Chapter 4. Divide-and-Conquer. Copyright 2007 Pearson Addison-Wesley. All rights reserved.

Chapter 4. Divide-and-Conquer. Copyright 2007 Pearson Addison-Wesley. All rights reserved. Chapter 4 Divide-and-Conquer Copyright 2007 Pearson Addison-Wesley. All rights reserved. Divide-and-Conquer The most-well known algorithm design strategy: 2. Divide instance of problem into two or more

More information

Copyright 2009, Artur Czumaj 1

Copyright 2009, Artur Czumaj 1 CS 244 Algorithm Design Instructor: Artur Czumaj Lecture 2 Sorting You already know sorting algorithms Now you will see more We will want to understand generic techniques used for sorting! Lectures: Monday

More information

Objec&ves. Review. Directed Graphs: Strong Connec&vity Greedy Algorithms

Objec&ves. Review. Directed Graphs: Strong Connec&vity Greedy Algorithms Objec&ves Directed Graphs: Strong Connec&vity Greedy Algorithms Ø Interval Scheduling Feb 7, 2018 CSCI211 - Sprenkle 1 Review Compare and contrast directed and undirected graphs What is a topological ordering?

More information

Divide-and-Conquer. The most-well known algorithm design strategy: smaller instances. combining these solutions

Divide-and-Conquer. The most-well known algorithm design strategy: smaller instances. combining these solutions Divide-and-Conquer The most-well known algorithm design strategy: 1. Divide instance of problem into two or more smaller instances 2. Solve smaller instances recursively 3. Obtain solution to original

More information

CS 6463: AT Computational Geometry Spring 2006 Convex Hulls Carola Wenk

CS 6463: AT Computational Geometry Spring 2006 Convex Hulls Carola Wenk CS 6463: AT Computational Geometry Spring 2006 Convex Hulls Carola Wenk 8/29/06 CS 6463: AT Computational Geometry 1 Convex Hull Problem Given a set of pins on a pinboard and a rubber band around them.

More information

In what follows, we will focus on Voronoi diagrams in Euclidean space. Later, we will generalize to other distance spaces.

In what follows, we will focus on Voronoi diagrams in Euclidean space. Later, we will generalize to other distance spaces. Voronoi Diagrams 4 A city builds a set of post offices, and now needs to determine which houses will be served by which office. It would be wasteful for a postman to go out of their way to make a delivery

More information

Input: n jobs (associated start time s j, finish time f j, and value v j ) for j = 1 to n M[j] = empty M[0] = 0. M-Compute-Opt(n)

Input: n jobs (associated start time s j, finish time f j, and value v j ) for j = 1 to n M[j] = empty M[0] = 0. M-Compute-Opt(n) Objec&ves Dnamic Programming Ø Wrapping up: weighted interval schedule Ø Ø Subset Sums Summar: Proper&es of Problems for DP Polnomial number of subproblems Solu&on to original problem can be easil computed

More information

Chapter 1 Divide and Conquer Algorithm Theory WS 2013/14 Fabian Kuhn

Chapter 1 Divide and Conquer Algorithm Theory WS 2013/14 Fabian Kuhn Chapter 1 Divide and Conquer Algorithm Theory WS 2013/14 Fabian Kuhn Number of Inversions Formal problem: Given: array,,,, of distinct elements Objective: Compute number of inversions 0 Example: 4, 1,

More information

Computational Geometry. Algorithm Design (10) Computational Geometry. Convex Hull. Areas in Computational Geometry

Computational Geometry. Algorithm Design (10) Computational Geometry. Convex Hull. Areas in Computational Geometry Computational Geometry Algorithm Design (10) Computational Geometry Graduate School of Engineering Takashi Chikayama Algorithms formulated as geometry problems Broad application areas Computer Graphics,

More information

100 points total. CSE 3353 Homework 2 Spring 2013

100 points total. CSE 3353 Homework 2 Spring 2013 Name: 100 points total CSE 3353 Homework 2 Spring 2013 Assignment is due at 9:30am on February 28. Submit a hard copy of the assignment, including a copy of your code and outputs as requested in the assignment.

More information

CSC Design and Analysis of Algorithms

CSC Design and Analysis of Algorithms CSC 8301- Design and Analysis of Algorithms Lecture 6 Divide and Conquer Algorithm Design Technique Divide-and-Conquer The most-well known algorithm design strategy: 1. Divide a problem instance into two

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 12: Sorting Algorithms MOUNA KACEM mouna@cs.wisc.edu Spring 2018 Outline 2 Last week Implementation of the three tree depth-traversal algorithms Implementation of the BinarySearchTree

More information

Lecture 15 : Review DRAFT

Lecture 15 : Review DRAFT CS/Math 240: Introduction to Discrete Mathematics 3/10/2011 Lecture 15 : Review Instructor: Dieter van Melkebeek Scribe: Dalibor Zelený DRAFT Today slectureservesasareviewofthematerialthatwillappearonyoursecondmidtermexam.

More information

CSC236 Week 6. Larry Zhang

CSC236 Week 6. Larry Zhang CSC236 Week 6 Larry Zhang 1 2 Drop date: Nov 9th jk, wait until the test marks are back Tutorial this week: algorithm analysis PS5 will be out by the end of this week 3 What we have learned so far We learned

More information

CSE 373: Data Structure & Algorithms Comparison Sor:ng

CSE 373: Data Structure & Algorithms Comparison Sor:ng CSE 373: Data Structure & Comparison Sor:ng Riley Porter Winter 2017 1 Course Logis:cs HW4 preliminary scripts out HW5 out à more graphs! Last main course topic this week: Sor:ng! Final exam in 2 weeks!

More information

Chapter 1 Divide and Conquer Algorithm Theory WS 2013/14 Fabian Kuhn

Chapter 1 Divide and Conquer Algorithm Theory WS 2013/14 Fabian Kuhn Chapter 1 Divide and Conquer Algorithm Theory WS 2013/14 Fabian Kuhn Divide And Conquer Principle Important algorithm design method Examples from Informatik 2: Sorting: Mergesort, Quicksort Binary search

More information

26 The closest pair problem

26 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 information

CMPSCI 311: Introduction to Algorithms Practice Final Exam

CMPSCI 311: Introduction to Algorithms Practice Final Exam CMPSCI 311: Introduction to Algorithms Practice Final Exam Name: ID: Instructions: Answer the questions directly on the exam pages. Show all your work for each question. Providing more detail including

More information

Lecture 2: Divide and Conquer

Lecture 2: Divide and Conquer Lecture 2: Divide and Conquer Paradigm Convex Hull Median finding Paradigm Given a problem of size n divide it into subproblems of size n, a 1, b >1. Solve each b subproblem recursively. Combine solutions

More information

Rank. Selection Problem

Rank. Selection Problem Rank Rank of an element is its position in ascending key order. rank(2) = 0 rank(15) = 5 rank(20) = 7 [2,6,7,8,10,15,18,20,25,30,35,40] Selection Problem Given n unsorted elements, determine the k th smallest

More information

Selection Problem. Rank. Divide-And-Conquer Selection. Selection By Sorting

Selection Problem. Rank. Divide-And-Conquer Selection. Selection By Sorting Rank Rank of an element is its position in ascending key order. rank(2) = 0 rank(15) = 5 rank(20) = 7 [2,6,7,8,10,15,18,20,25,30,35,40] Selection Problem Given n unsorted elements, determine the k th smallest

More information

1/60. Geometric Algorithms. Lecture 1: Introduction. Convex Hulls

1/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 information

07 B: Sorting II. CS1102S: Data Structures and Algorithms. Martin Henz. March 5, Generated on Friday 5 th March, 2010, 08:31

07 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 information

Randomized algorithms. Inge Li Gørtz

Randomized algorithms. Inge Li Gørtz Randomized algorithms Inge Li Gørtz 1 Randomized algorithms Today What are randomized algorithms? Properties of randomized algorithms Three examples: Median/Select. Quick-sort Closest pair of points 2

More information

Greedy, Divide and Conquer

Greedy, Divide and Conquer Greedy, ACA, IIT Kanpur October 5, 2013 Greedy, Outline 1 Greedy Algorithms 2 3 4 Greedy, Greedy Algorithms Greedy algorithms are generally used in optimization problems Greedy, Greedy Algorithms Greedy

More information

Lecture 6: Divide-and-Conquer

Lecture 6: Divide-and-Conquer Lecture 6: Divide-and-Conquer COSC242: Algorithms and Data Structures Brendan McCane Department of Computer Science, University of Otago Types of Algorithms In COSC242, we will be looking at 3 general

More information

Computer Science 385 Analysis of Algorithms Siena College Spring Topic Notes: Divide and Conquer

Computer Science 385 Analysis of Algorithms Siena College Spring Topic Notes: Divide and Conquer Computer Science 385 Analysis of Algorithms Siena College Spring 2011 Topic Notes: Divide and Conquer Divide and-conquer is a very common and very powerful algorithm design technique. The general idea:

More information

Divide-and-Conquer. Dr. Yingwu Zhu

Divide-and-Conquer. Dr. Yingwu Zhu Divide-and-Conquer Dr. Yingwu Zhu Divide-and-Conquer The most-well known algorithm design technique: 1. Divide instance of problem into two or more smaller instances 2. Solve smaller instances independently

More information

Algorithms for GIS:! Quadtrees

Algorithms for GIS:! Quadtrees Algorithms for GIS: Quadtrees Quadtree A data structure that corresponds to a hierarchical subdivision of the plane Start with a square (containing inside input data) Divide into 4 equal squares (quadrants)

More information

Divide and Conquer Algorithms

Divide and Conquer Algorithms Divide and Conquer Algorithms T. M. Murali February 19, 2009 Divide and Conquer Break up a problem into several parts. Solve each part recursively. Solve base cases by brute force. Efficiently combine

More information

(Refer Slide Time: 01.26)

(Refer Slide Time: 01.26) Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture # 22 Why Sorting? Today we are going to be looking at sorting.

More information

Optimal Compression of a Polyline with Segments and Arcs

Optimal Compression of a Polyline with Segments and Arcs Optimal Compression of a Polyline with Segments and Arcs Alexander Gribov Esri 380 New York Street Redlands, CA 92373 Email: agribov@esri.com arxiv:1604.07476v5 [cs.cg] 10 Apr 2017 Abstract This paper

More information

CSE 5311 Notes 13: Computational Geometry

CSE 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 information

Principles of Algorithm Design

Principles of Algorithm Design Principles of Algorithm Design When you are trying to design an algorithm or a data structure, it s often hard to see how to accomplish the task. The following techniques can often be useful: 1. Experiment

More information

Lecture 34 Fall 2018 Wednesday November 28

Lecture 34 Fall 2018 Wednesday November 28 Greedy Algorithms Oliver W. Layton CS231: Data Structures and Algorithms Lecture 34 Fall 2018 Wednesday November 28 Plan Friday office hours: 3-4pm instead of 1-2pm Dijkstra's algorithm example Minimum

More information

Geometric Computation: Introduction. Piotr Indyk

Geometric Computation: Introduction. Piotr Indyk Geometric Computation: Introduction Piotr Indyk Welcome to 6.850! Overview and goals Course Information Closest pair Signup sheet Geometric Computation Geometric computation occurs everywhere: Robotics:

More information

CS 410/584, Algorithm Design & Analysis, Lecture Notes 8!

CS 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 information

Divided-and-Conquer for Voronoi Diagrams Revisited. Supervisor: Ben Galehouse Presenter: Xiaoqi Cao

Divided-and-Conquer for Voronoi Diagrams Revisited. Supervisor: Ben Galehouse Presenter: Xiaoqi Cao Divided-and-Conquer for Voronoi Diagrams Revisited Supervisor: Ben Galehouse Presenter: Xiaoqi Cao Outline Introduction Generalized Voronoi Diagram Algorithm for building generalized Voronoi Diagram Applications

More information

CPSC W2 Midterm #2 Sample Solutions

CPSC W2 Midterm #2 Sample Solutions CPSC 320 2014W2 Midterm #2 Sample Solutions March 13, 2015 1 Canopticon [8 marks] Classify each of the following recurrences (assumed to have base cases of T (1) = T (0) = 1) into one of the three cases

More information

Sorting. Data Structures and Algorithms CSE 373 SU 18 BEN JONES 1

Sorting. Data Structures and Algorithms CSE 373 SU 18 BEN JONES 1 Sorting Data Structures and lgorithms CSE 373 SU 18 BEN JONES 1 Warmup Discuss with your neighbors: What considerations do we think about when choosing a sorting algorithm? So far we have seen: selection

More information

Scan and its Uses. 1 Scan. 1.1 Contraction CSE341T/CSE549T 09/17/2014. Lecture 8

Scan and its Uses. 1 Scan. 1.1 Contraction CSE341T/CSE549T 09/17/2014. Lecture 8 CSE341T/CSE549T 09/17/2014 Lecture 8 Scan and its Uses 1 Scan Today, we start by learning a very useful primitive. First, lets start by thinking about what other primitives we have learned so far? The

More information

CS 372: Computational Geometry Lecture 3 Line Segment Intersection

CS 372: Computational Geometry Lecture 3 Line Segment Intersection 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

More information

Parallel Sorting Algorithms

Parallel Sorting Algorithms CSC 391/691: GPU Programming Fall 015 Parallel Sorting Algorithms Copyright 015 Samuel S. Cho Sorting Algorithms Review Bubble Sort: O(n ) Insertion Sort: O(n ) Quick Sort: O(n log n) Heap Sort: O(n log

More information

CS61B Lectures # Purposes of Sorting. Some Definitions. Classifications. Sorting supports searching Binary search standard example

CS61B Lectures # Purposes of Sorting. Some Definitions. Classifications. Sorting supports searching Binary search standard example Announcements: CS6B Lectures #27 28 We ll be runningapreliminarytestingrun for Project #2 on Tuesday night. Today: Sorting algorithms: why? Insertion, Shell s, Heap, Merge sorts Quicksort Selection Distribution

More information

Rec 8 Notes. 1 Divide-and-Conquer Convex Hull. 1.1 Algorithm Idea. 1.2 Algorithm. Here s another random Divide-And-Conquer algorithm.

Rec 8 Notes. 1 Divide-and-Conquer Convex Hull. 1.1 Algorithm Idea. 1.2 Algorithm. Here s another random Divide-And-Conquer algorithm. Divide-and-Conquer Convex Hull Here s another random Divide-And-Conquer algorithm. Recall, possibly from CS 2, that the convex hull H(Q) of a set of points Q is the smallest convex set containing Q (that

More information

Problem. 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. 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 information

CSCI 104 Log Structured Merge Trees. Mark Redekopp

CSCI 104 Log Structured Merge Trees. Mark Redekopp 1 CSCI 10 Log Structured Merge Trees Mark Redekopp Series Summation Review Let n = 1 + + + + k = σk i=0 n = k+1-1 i. What is n? What is log (1) + log () + log () + log (8)++ log ( k ) = 0 + 1 + + 3+ +

More information

Computational Geometry Overview from Cormen, et al.

Computational Geometry Overview from Cormen, et al. UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2014 Computational Geometry Overview from Cormen, et al. Chapter 33 (with additional material from other sources) 1

More information

CS1 Lecture 30 Apr. 2, 2018

CS1 Lecture 30 Apr. 2, 2018 CS1 Lecture 30 Apr. 2, 2018 HW 7 available very different than others you need to produce a written document based on experiments comparing sorting methods If you are not using a Python (like Anaconda)

More information

Divide and Conquer 4-0

Divide and Conquer 4-0 Divide and Conquer 4-0 Divide-and-Conquer The most-well known algorithm design strategy: 1. Divide instance of problem into two or more smaller instances 2. Solve smaller instances recursively 3. Obtain

More information

A 0 A 1... A i 1 A i,..., A min,..., A n 1 in their final positions the last n i elements After n 1 passes, the list is sorted.

A 0 A 1... A i 1 A i,..., A min,..., A n 1 in their final positions the last n i elements After n 1 passes, the list is sorted. CS6402 Design and Analysis of Algorithms _ Unit II 2.1 UNIT II BRUTE FORCE AND DIVIDE-AND-CONQUER 2.1 BRUTE FORCE Brute force is a straightforward approach to solving a problem, usually directly based

More information

Comparison Sorts. Chapter 9.4, 12.1, 12.2

Comparison Sorts. Chapter 9.4, 12.1, 12.2 Comparison Sorts Chapter 9.4, 12.1, 12.2 Sorting We have seen the advantage of sorted data representations for a number of applications Sparse vectors Maps Dictionaries Here we consider the problem of

More information

Quicksort. Repeat the process recursively for the left- and rightsub-blocks.

Quicksort. Repeat the process recursively for the left- and rightsub-blocks. Quicksort As the name implies, this is the fastest known sorting algorithm in practice. It is excellent for average input but bad for the worst-case input. (you will see later). Basic idea: (another divide-and-conquer

More information

CPE702 Algorithm Analysis and Design Week 7 Algorithm Design Patterns

CPE702 Algorithm Analysis and Design Week 7 Algorithm Design Patterns CPE702 Algorithm Analysis and Design Week 7 Algorithm Design Patterns Pruet Boonma pruet@eng.cmu.ac.th Department of Computer Engineering Faculty of Engineering, Chiang Mai University Based on Slides by

More information

17/05/2018. Outline. Outline. Divide and Conquer. Control Abstraction for Divide &Conquer. Outline. Module 2: Divide and Conquer

17/05/2018. Outline. Outline. Divide and Conquer. Control Abstraction for Divide &Conquer. Outline. Module 2: Divide and Conquer Module 2: Divide and Conquer Divide and Conquer Control Abstraction for Divide &Conquer 1 Recurrence equation for Divide and Conquer: If the size of problem p is n and the sizes of the k sub problems are

More information

CSCE 411 Design and Analysis of Algorithms

CSCE 411 Design and Analysis of Algorithms CSCE 411 Design and Analysis of Algorithms Set 3: Divide and Conquer Slides by Prof. Jennifer Welch Spring 2014 CSCE 411, Spring 2014: Set 3 1 General Idea of Divide & Conquer 1. Take your problem and

More information

Computer Science 331

Computer Science 331 Computer Science 331 Merge Sort Wayne Eberly Department of Computer Science University of Calgary Lecture #23 Introduction Merge Sort Merging Conclusions Outline Introduction Merge Sort is is an asymptotically

More information

Module 2: Classical Algorithm Design Techniques

Module 2: Classical Algorithm Design Techniques Module 2: Classical Algorithm Design Techniques Dr. Natarajan Meghanathan Associate Professor of Computer Science Jackson State University Jackson, MS 39217 E-mail: natarajan.meghanathan@jsums.edu Module

More information

CSE 101. Algorithm Design and Analysis Miles Jones Office 4208 CSE Building Lecture 17: Divide and Conquer Design examples.

CSE 101. Algorithm Design and Analysis Miles Jones Office 4208 CSE Building Lecture 17: Divide and Conquer Design examples. CSE 101 Algorithm Design and Analysis Miles Jones mej016@eng.ucsd.edu Office 4208 CSE Building Lecture 17: Divide and Conquer Design examples. DIVIDE AND CONQUER EXAMPLES (GREATEST OVERLAP.) Given a list

More information

3D convex hulls. Computational Geometry [csci 3250] Laura Toma Bowdoin College

3D convex hulls. Computational Geometry [csci 3250] Laura Toma Bowdoin College 3D convex hulls Computational Geometry [csci 3250] Laura Toma Bowdoin College Convex Hulls The problem: Given a set P of points, compute their convex hull 2D 3D 2D 3D polygon polyhedron Polyhedron region

More information

(Master Course) Mohammad Farshi Department of Computer Science, Yazd University. Yazd Univ. Computational Geometry.

(Master Course) Mohammad Farshi Department of Computer Science, Yazd University. Yazd Univ. Computational Geometry. 1 / 17 (Master Course) Mohammad Farshi Department of Computer Science, Yazd University 1392-1 2 / 17 : Mark de Berg, Otfried Cheong, Marc van Kreveld, Mark Overmars, Algorithms and Applications, 3rd Edition,

More information

Other Voronoi/Delaunay Structures

Other Voronoi/Delaunay Structures Other Voronoi/Delaunay Structures Overview Alpha hulls (a subset of Delaunay graph) Extension of Voronoi Diagrams Convex Hull What is it good for? The bounding region of a point set Not so good for describing

More information

Searching, Sorting. part 1

Searching, Sorting. part 1 Searching, Sorting part 1 Week 3 Objectives Searching: binary search Comparison-based search: running time bound Sorting: bubble, selection, insertion, merge Sorting: Heapsort Comparison-based sorting

More information

Planar convex hulls (I) Computational Geometry [csci 3250] Laura Toma Bowdoin College

Planar convex hulls (I) Computational Geometry [csci 3250] Laura Toma Bowdoin College Planar convex hulls (I) Computational Geometry [csci 3250] Laura Toma Bowdoin College Convex Hull Given a set P of points in 2D, their convex hull is the smallest convex polygon that contains all points

More information

Analyze the obvious algorithm, 5 points Here is the most obvious algorithm for this problem: (LastLargerElement[A[1..n]:

Analyze 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 information

08 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, 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 information