Lecture 15, Winter 2019 Closest Pair, Multiplication

Slides:



Advertisements
Similar presentations
A simple example finding the maximum of a set S of n numbers.
Advertisements

Order Statistics(Selection Problem) A more interesting problem is selection:  finding the i th smallest element of a set We will show: –A practical randomized.
CS 3343: Analysis of Algorithms Lecture 14: Order Statistics.
1 Selection --Medians and Order Statistics (Chap. 9) The ith order statistic of n elements S={a 1, a 2,…, a n } : ith smallest elements Also called selection.
Introduction to Algorithms Jiafen Liu Sept
Chapter 6 Divide and Conquer  Introduction  Binary Search  Mergesort  The Divide and Conquer Paradigm  Quicksort  Multiplication of Large Integers.
Lectures on Recursive Algorithms1 COMP 523: Advanced Algorithmic Techniques Lecturer: Dariusz Kowalski.
Algorithm Design Techniques: Divide and Conquer. Introduction Divide and conquer – algorithm makes at least two recursive calls Subproblems should not.
Divide and Conquer. Recall Complexity Analysis – Comparison of algorithm – Big O Simplification From source code – Recursive.
Spring 2015 Lecture 5: QuickSort & Selection
Nattee Niparnan. Recall  Complexity Analysis  Comparison of Two Algos  Big O  Simplification  From source code  Recursive.
CS38 Introduction to Algorithms Lecture 7 April 22, 2014.
Algorithm Design Strategy Divide and Conquer. More examples of Divide and Conquer  Review of Divide & Conquer Concept  More examples  Finding closest.
Lecture 31 CSE 331 Nov 16, Jeff is out of town this week No regular recitation or Jeff’s normal office hours I’ll hold extra Question sessions Mon,
CSE 421 Algorithms Richard Anderson Lecture 13 Divide and Conquer.
Design and Analysis of Algorithms - Chapter 41 Divide and Conquer The most well known algorithm design strategy: 1. Divide instance of problem into two.
Lecture 33 CSE 331 Nov 17, Online office hours Alex will host the office hours.
CSE 421 Algorithms Richard Anderson Lecture 11 Recurrences.
Sorting (Part II: Divide and Conquer) CSE 373 Data Structures Lecture 14.
Prof. Swarat Chaudhuri COMP 482: Design and Analysis of Algorithms Spring 2013 Lecture 12.
Order Statistics ● The ith order statistic in a set of n elements is the ith smallest element ● The minimum is thus the 1st order statistic ● The maximum.
CS 361 – Chapters 8-9 Sorting algorithms –Selection, insertion, bubble, “swap” –Merge, quick, stooge –Counting, bucket, radix How to select the n-th largest/smallest.
Divide and Conquer Applications Sanghyun Park Fall 2002 CSE, POSTECH.
Order Statistics(Selection Problem)
CSE 421 Algorithms Lecture 15 Closest Pair, Multiplication.
Young CS 331 D&A of Algo. Topic: Divide and Conquer1 Divide-and-Conquer General idea: Divide a problem into subprograms of the same kind; solve subprograms.
David Luebke 1 6/26/2016 CS 332: Algorithms Linear-Time Sorting Continued Medians and Order Statistics.
David Luebke 1 7/2/2016 CS 332: Algorithms Linear-Time Sorting: Review + Bucket Sort Medians and Order Statistics.
Chapter 2. Divide-and-conquer Algorithms
Introduction to Algorithms: Divide-n-Conquer Algorithms
Chapter 4 Divide-and-Conquer
Randomized Algorithms
Chapter 4 Divide-and-Conquer
Lecture 3: Divide-and-conquer
CSCE350 Algorithms and Data Structure
Order Statistics(Selection Problem)
Richard Anderson Lecture 14 Divide and Conquer
Divide and Conquer / Closest Pair of Points Yin Tat Lee
Unit-2 Divide and Conquer
Randomized Algorithms
Punya Biswas Lecture 15 Closest Pair, Multiplication
Topic: Divide and Conquer
Richard Anderson Lecture 11 Recurrences
Richard Anderson Lecture 13 Divide and Conquer
CS 3343: Analysis of Algorithms
Richard Anderson Lecture 14 Inversions, Multiplication, FFT
Lecture 32 CSE 331 Nov 14, 2011.
Lecture 29 CSE 331 Nov 8, 2017.
Divide-and-Conquer The most-well known algorithm design strategy:
CS 3343: Analysis of Algorithms
Lecture 31 CSE 331 Nov 14, 2012.
Order Statistics Def: Let A be an ordered set containing n elements. The i-th order statistic is the i-th smallest element. Minimum: 1st order statistic.
CSE 373 Data Structures and Algorithms
Chapter 9: Medians and Order Statistics
Lecture 30 CSE 331 Nov 12, 2012.
CSCI 256 Data Structures and Algorithm Analysis Lecture 12
Richard Anderson Lecture 14 Divide and Conquer
Lecture 31 CSE 331 Nov 11, 2011.
David Kauchak cs161 Summer 2009
The Selection Problem.
Richard Anderson Lecture 14, Winter 2019 Divide and Conquer
Richard Anderson Lecture 14 Divide and Conquer
Divide-and-Conquer 7 2  9 4   2   4   7
Lecture 15 Closest Pair, Multiplication
Richard Anderson Lecture 12, Winter 2019 Recurrences
Lecture 27 CSE 331 Nov 4, 2016.
Given a list of n  8 integers, what is the runtime bound on the optimal algorithm that sorts the first eight? O(1) O(log n) O(n) O(n log n) O(n2)
Richard Anderson Lecture 12 Recurrences
Richard Anderson Lecture 13 Divide and Conquer
Presentation transcript:

Lecture 15, Winter 2019 Closest Pair, Multiplication CSE 421 Algorithms Lecture 15, Winter 2019 Closest Pair, Multiplication

Announcements Midterm returned with solution set Next week, Dynamic Programming Chapter 6 Midterm Average: 50.5

Divide and Conquer Algorithms Mergesort, Quicksort Strassen’s Algorithm Inversion counting Median Closest Pair Algorithm (2d) Integer Multiplication (Karatsuba’s Algorithm) FFT Polynomial Multiplication Convolution

Median: BFPRT Algorithm Select(A, k){ x = BFPRT(A) S1 = {y in A | y < x}; S2 = {y in A | y > x}; S3 = {y in A | y = x} if (|S2| >= k) return Select(S2, k) else if (|S2| + |S3| >= k) return x else return Select(S1, k - |S2| - |S3|) } S1 S3 S2 BFPRT(A){ n = |A| Split A into n/5 sets of size 5 M be the set of medians of these sets x = Select(M, n/10) /* x is the median of M */ return x }

BFPRT Recurrence T(n) <= T(3n/4) + T(n/5) + c n Prove that T(n) <= 20 c n

Median In practice, select the pivot by choosing an element at random Heuristics such as median-of-three gives improved performance BFPRT is NOT a practical algorithm Why groups of five? Odd number Three does not allow linear bound to be proven Seven gives a worse constant factor

Closest Pair Problem (2D) Given a set of points find the pair of points p, q that minimizes dist(p, q)

Divide and conquer If we solve the problem on two subsets, does it help? (Separate by median x coordinate) d1 d2

Packing Lemma Suppose that the minimum distance between points is at least d, what is the maximum number of points that can be packed in a ball of radius d?

Combining Solutions Suppose the minimum separation from the sub problems is d In looking for cross set closest pairs, we only need to consider points with d of the boundary How many cross border interactions do we need to test?

A packing lemma bounds the number of distances to check

Details Preprocessing: sort points by y Merge step Select points in boundary zone For each point in the boundary Find highest point on the other side that is at most d above Find lowest point on the other side that is at most d below Compare with the points in this interval (there are at most 6)

Identify the pairs of points that are compared in the merge step following the recursive calls

Algorithm run time After preprocessing: T(n) = cn + 2 T(n/2)

Integer Arithmetic 9715480283945084383094856701043643845790217965702956767 + 1242431098234099057329075097179898430928779579277597977 Runtime for standard algorithm to add two n digit numbers: 2095067093034680994318596846868779409766717133476767930 X 5920175091777634709677679342929097012308956679993010921 Runtime for standard algorithm to multiply two n digit numbers:

Recursive Multiplication Algorithm (First attempt) x = x1 2n/2 + x0 y = y1 2n/2 + y0 xy = (x1 2n/2 + x0) (y1 2n/2 + y0) = x1y1 2n + (x1y0 + x0y1)2n/2 + x0y0 Recurrence: Run time:

Simple algebra x = x1 2n/2 + x0 y = y1 2n/2 + y0 xy = x1y1 2n + (x1y0 + x0y1) 2n/2 + x0y0 p = (x1 + x0)(y1 + y0) = x1y1 + x1y0 + x0y1 + x0y0

Karatsuba’s Algorithm Multiply n-digit integers x and y Let x = x1 2n/2 + x0 and y = y1 2n/2 + y0 Recursively compute a = x1y1 b = x0y0 p = (x1 + x0)(y1 + y0) Return a2n + (p – a – b)2n/2 + b Recurrence: T(n) = 3T(n/2) + cn log2 3 = 1.58496250073…

Next week Dynamic Programming!