Richard Anderson Lecture 13 Divide and Conquer

Slides:



Advertisements
Similar presentations
Theory of Computing Lecture 3 MAS 714 Hartmut Klauck.
Advertisements

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
Spring 2015 Lecture 5: QuickSort & Selection
CS38 Introduction to Algorithms Lecture 7 April 22, 2014.
Chapter 4: Divide and Conquer The Design and Analysis of Algorithms.
CSE 421 Algorithms Richard Anderson Lecture 12 Recurrences.
Median, order statistics. Problem Find the i-th smallest of n elements.  i=1: minimum  i=n: maximum  i= or i= : median Sol: sort and index the i-th.
CSE 421 Algorithms Richard Anderson Lecture 13 Divide and Conquer.
CSE 421 Algorithms Richard Anderson Lecture 11 Recurrences.
Sorting (Part II: Divide and Conquer) CSE 373 Data Structures Lecture 14.
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.
Divide and Conquer Applications Sanghyun Park Fall 2002 CSE, POSTECH.
CSE 421 Algorithms Lecture 15 Closest Pair, Multiplication.
Lecture 5 Today, how to solve recurrences We learned “guess and proved by induction” We also learned “substitution” method Today, we learn the “master.
Introduction to Complexity Analysis. Computer Science, Silpakorn University 2 Complexity of Algorithm algorithm คือ ขั้นตอนการคำนวณ ที่ถูกนิยามไว้อย่างชัดเจนโดยจะ.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 11.
Today’s Material Sorting: Definitions Basic Sorting Algorithms
CSE 421 Algorithms Richard Anderson Lecture 13 Recurrences, Part 2.
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.
Advanced Algorithms Analysis and Design
Chapter 11 Sorting Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich, Tamassia and Mount.
Introduction to Algorithms
Fundamentals of Algorithms MCS - 2 Lecture # 11
Chapter 5 Divide & conquer
Randomized Algorithms
Chapter 4 Divide-and-Conquer
Divide and Conquer.
Divide and Conquer – and an Example QuickSort
Algorithm Design Methods
Divide-and-Conquer The most-well known algorithm design strategy:
Richard Anderson Lecture 14 Divide and Conquer
Randomized Algorithms
Punya Biswas Lecture 15 Closest Pair, Multiplication
Richard Anderson Lecture 13 Recurrences and Divide and Conquer
Lecture 30 CSE 331 Nov 11, 2016.
Topic: Divide and Conquer
Richard Anderson Lecture 11 Recurrences
Richard Anderson Lecture 11 Minimum Spanning Trees
Richard Anderson Lecture 12 Recurrences and Divide and Conquer
Richard Anderson Lecture 14 Inversions, Multiplication, FFT
Divide-and-Conquer The most-well known algorithm design strategy:
Lecture 32 CSE 331 Nov 14, 2011.
Lecture 29 CSE 331 Nov 8, 2017.
Richard Anderson Lecture 13 Recurrences, Part 2
Lecture 30 CSE 331 Nov 10, 2017.
Divide-and-Conquer The most-well known algorithm design strategy:
Merge and Count Merge and count step.
Merge and Count Merge and count step.
Merge and Count Merge and count step.
CSE 373 Data Structures and Algorithms
CSCI 256 Data Structures and Algorithm Analysis Lecture 12
Topic: Divide and Conquer
Lecture 15, Winter 2019 Closest Pair, Multiplication
Richard Anderson Lecture 14 Divide and Conquer
Lecture 31 CSE 331 Nov 11, 2011.
CS200: Algorithm Analysis
The Selection Problem.
Richard Anderson Lecture 13, Winter 2019 Recurrences, Part 2
Richard Anderson Lecture 14, Winter 2019 Divide and Conquer
Richard Anderson Lecture 14 Divide and Conquer
Lecture 15 Closest Pair, Multiplication
Richard Anderson Lecture 12, Winter 2019 Recurrences
CS200: Algorithm Analysis
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)
Divide and Conquer Merge sort and quick sort Binary search
Richard Anderson Lecture 12 Recurrences
Richard Anderson Lecture 13 Divide and Conquer
Presentation transcript:

Richard Anderson Lecture 13 Divide and Conquer CSE 421 Algorithms Richard Anderson Lecture 13 Divide and Conquer

What you really need to know about recurrences Work per level changes geometrically with the level Geometrically increasing (x > 1) The bottom level wins Geometrically decreasing (x < 1) The top level wins Balanced (x = 1) Equal contribution

T(n) = aT(n/b) + nc Balanced: a = bc Increasing: a > bc Decreasing: a < bc

Classify the following recurrences (Increasing, Decreasing, Balanced) T(n) = n + 5T(n/8) T(n) = n + 9T(n/8) T(n) = n2 + 4T(n/2) T(n) = n3 + 7T(n/2) T(n) = n1/2 + 3T(n/4)

Divide and Conquer Algorithms Split into sub problems Recursively solve the problem Combine solutions Make progress in the split and combine stages Quicksort – progress made at the split step Mergesort – progress made at the combine step

Closest Pair Problem 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)

Inversion Problem Let a1, . . . an be a permutation of 1 . . n (ai, aj) is an inversion if i < j and ai > aj Problem: given a permutation, count the number of inversions This can be done easily in O(n2) time Can we do better? 4, 6, 1, 7, 3, 2, 5

Application Counting inversions can be use to measure how close ranked preferences are People rank 20 movies, based on their rankings you cluster people who like that same type of movie

Counting Inversions Count inversions on lower half 11 12 4 1 7 2 3 15 9 5 16 8 6 13 10 14 Count inversions on lower half Count inversions on upper half Count the inversions between the halves

Count the Inversions 11 12 4 1 7 2 3 15 9 5 16 8 6 13 10 14 11 12 4 1 7 2 3 15 9 5 16 8 6 13 10 14 11 12 4 1 7 2 3 15 9 5 16 8 6 13 10 14

Problem – how do we count inversions between sub problems in O(n) time? Solution – Count inversions while merging 1 2 3 4 7 11 12 15 5 6 8 9 10 13 14 16 Standard merge algorithms – add to inversion count when an element is moved from the upper array to the solution

Use the merge algorithm to count inversions 1 4 11 12 2 3 7 15 5 8 9 16 6 10 13 14