SlideShare a Scribd company logo
1 of 24
Design and
Analysis of
Algorithms
DIVIDE AND CONQUER
PART II
CLOSEST PAIR OF POINTS
MEDIAN FINDING
SELECTION ALGORITHMS
 Instructor
Prof. Amrinder Arora
amrinder@gwu.edu
Please copy TA on emails
Please feel free to call as well

 Available for study sessions
Science and Engineering Hall
GWU
Algorithms Divide and Conquer - Part II 2
LOGISTICS
Algorithms
Analysis
Asymptotic
NP-
Completeness
Design
D&C
DP
Greedy
Graph
B&B
Applications
Algorithms Divide and Conquer - Part II 3
WHERE WE ARE
 A technique to solve complex problems by breaking into
smaller instances of the problem and combining the results
 Recursive methodology – Smaller instances of the same type of
problem
 Typically used with:
 Principle of Mathematical Induction – For proving correctness
 Recurrence relation solving – For computing time (and/or space)
complexity
Algorithms Divide and Conquer - Part II 4
DIVIDE AND CONQUER
 Generalization step: Given an array and indexes i and j (start
and end) to sort that portion of it
 Algorithm MergeSort (input: A,i,j) {
if input size is small, solve differently and return
int k=(i+j)/2
MergeSort(A,i,k)
MergeSort(A,k+1,j)
Merge(A,i,k,k+1,j)
}
• T(n) = 2T(n/2) + n
• T(n) = O(n log n)
[Discussed in previous lectures.]
Algorithms Divide and Conquer - Part II 5
MERGESORT
 quicksort(A,p,r)
if (p < r) {
q = partition (A,p,r)
quicksort(A,p,q-1)
quicksort(A,q+1,r)
}
• Time complexity = ?
[Discussed in previous lectures.]
Algorithms Divide and Conquer - Part II 6
QUICKSORT
 Given an array of unsorted numbers, how to find the median?
 Option 1: Sort and return a[n/2]
 That takes O(n log n) time. Is there a more efficient
algorithm?
Algorithms Divide and Conquer - Part II 7
MEDIAN FINDING
 Step 1: Generalize the problem
 Selection (A, k): Returns k-th smallest element in given array.
For example:
 Selection (A,1) = Smallest
 Selection(A,n) = Largest // n is the array size.
 Selection(A,n/2) = Median
 Selection algorithms:
http://en.wikipedia.org/wiki/Selection_algorithm
 Also known as order statistic.
 Generalization of largest, smallest, median, etc. problems.
 This generalization step is very important for recursive calls!
Algorithms Divide and Conquer - Part II 8
MEDIAN FINDING
Selection (A,k)
Partition the array A
Suppose, the partition element lands at location k’
If (k == k’) {
return x // Great, we really got lucky.
}
If (k < k’) {
return Selection (A’,k) // Recursive call. Discard A”
}
If (k > k’) {
return Selection (A”,k-k’) // Recursive call. Discard A’
}
Algorithms Divide and Conquer - Part II 9
SELECTION – GENERAL TEMPLATE
 The main complication (as in case of Quicksort) is to find a
good partition. If the partition is very uneven, the algorithm
may not be efficient.
 We have two good choices:
 Use probability to find a good partition by trying repeatedly
 Find a good partition deterministically
 In the coming few slides, we explore both of these methods.
Algorithms Divide and Conquer - Part II 10
SELECTION – TWO APPROACHES
 Partition randomly.
 Define: A “good” partition is something that lands between the
middle half, that is between ¼ and ¾ of the array.
 You can find a “good” partition with probability ½
 Expected number of times that you have to do a partition until
you get a “good” partition = 2
 Suppose the good partition “lands” at location k’, where n/4 <=
k’ <= 3n/4
 Depending upon value of k and k’, we make the appropriate
recursive call, as specified in general template.
 After partition, we remove at least 25% of the array.
 T(n) <= 2n + T(0.75 n) // 2 reflects the expected # of times
that we have to do the partition
 T(n) <= cn // Using substitution method
 Therefore, T(n) = O(n)
Algorithms Divide and Conquer - Part II 11
SELECTION – PROBABILISTIC METHOD
 Divide the array into groups of 5 (or 7)
 Sort the small groups
 Find the median of the medians
 Partition the array on that median
x x x x x ......... x x x x x
x x x x x ......... x x x x x
x x x x x ......... x x x x x
x x x x x ......... x x x x x
x x x x x ......... x x x x x
Algorithms Divide and Conquer - Part II 12
SELECTION – QUICKSELECT ALGORITHM
 Say x = the median of median
 Then at least 30% of elements are <= x
 At least 30% of elements are >= x
 We use this x to be the partition element
 Suppose x “lands” at location k’, where 3n/10 <= k’ <= 7n/10
 Depending upon value of k and k’, we make the appropriate
recursive call, as specified in general template.
 Depending upon the value of k, either the left side of the
partition or the right side will be discarded. In either case, we
eliminate at least 30% of data.
 We note that there are 2 recursive calls – 1st call to find the
median of medians, and 2nd call after removing 25% of
elements
Algorithms Divide and Conquer - Part II 13
QUICKSELECT (CONT.)
 T(n) = cn + T(n/5) + T(7n/10)
 Proof that T(n) is linear, that is O(n), by substitution method
(Using Principle of Mathematical Induction)
We claim that T(n) <= 10 cn for all values of n < N
T(N/5) <= 2cN
T(7N/10) <= 7cN
 T(N) <= cN + 2cN + 7cN = 10cN
 The inequality holds for N
 By principle of mathematical induction, inequality holds for
all values of n.
 Therefore, T(n) = O(n)
Algorithms Divide and Conquer - Part II 14
QUICKSELECT – ANALYSIS
 Given n points on the plane, find the closest pair of points.
 http://en.wikipedia.org/wiki/Closest_pair_of_points_problem
 Textbook section 4.7
Algorithms Divide and Conquer - Part II 15
DIVIDE AND CONQUER – ANOTHER
APPLICATION
 Naïve algorithm requires O(n2) time – simply compute all
distances and find the minimum.
 We are interested in a divide and conquer approach.
 We remember that there is a signification difference between
O(n2) time algorithm and O(n log n) time algorithm. For
example, latter can easily be run with a trillion points, the
O(n2) algorithm, not so much.
Algorithms Divide and Conquer - Part II 16
CLOSEST PAIR OF POINTS
 Divide and Conquer approach:
1. Split the set of points into two equal-sized subsets by finding the
median of the x-dimensions of the points.
2. Solve the problem recursively for subsets to the left and right
subsets. Thus, there are two recursive calls.
3. Find the minimal distance among the pair of points in which one
point lies on the left of the dividing vertical and the second point
lies to the right.
 T(n) = cn + 2T(n/2) + f(n), where:
 cn represents the time spent in Step 1 (linear time median finding)
 2T(n/2) is time spent in two recursive calls in Step 2.
 f(n) is the time spent in step 3, that is, time to find the minimum
distance among the pairs, where one point lies to the left of the
dividing vertical, and the second point lies to the right.
Algorithms Divide and Conquer - Part II 17
CLOSEST PAIR OF POINTS (CONT.)
 T(n) = 2T(n/2) + cn + f(n)
 If f(n) = O(n2), then, T(n) = O(n2)
 If f(n) = O(n), then T(n) = O(n log n)
 Main complication then is to bound f(n)
 If we can do f(n) in linear time, we will have an O(n log n) time
algorithm.
 In the next couple of slides, we discuss indeed how this can
be done in linear time.
Algorithms Divide and Conquer - Part II 18
CLOSEST PAIR OF POINTS (CONT.)
 We define:
 1 = Minimum distance found in the left side
 2 = Minimum distance found in the right side
  = Minimum of 1 and 2
 Firstly, we are only interested in the points that are within a
distance  of the dividing vertical.
 For a point p1 on the left side of the dividing vertical, we are
only interested in:
 Points that are on the right side of the vertical, and within a distance
 from the dividing vertical
 Points that are within a vertical distance  from the point p1.
Algorithms Divide and Conquer - Part II 19
CLOSEST PAIR OF POINTS (CONT.)
Algorithms Divide and Conquer - Part II 20
CLOSEST PAIR OF POINTS (CONT.)
 Thus for a point p1, there can only be 6 points of interest for
that point.
 Even if there are n/2 points to the left of the dividing vertical
and within a distance , still that only means 3n pairs to
consider
 Therefore, f(n) = O(n)
 Therefore, T(n) = 2T(n/2) + O(n)
 Therefore, T(n) = O(n log n)
Algorithms Divide and Conquer - Part II 21
CLOSEST PAIR OF POINTS (CONT.)
 D&C – An interesting technique for solving problems
 Three different ways to solve recurrence relations
 Unfolding method
 Substitution (guess and prove method)
 Master Theorem – Another Method for solving Recurrence Relations
 QuickSelect – O(n) time algorithm for selecting k-th largest
element in an unsorted array.
 The constant is rather large, use this algorithm with caution
 Closest pair of points – An interesting O(n log n) time
recursive algorithm for finding the closest pair of points.
Algorithms Divide and Conquer - Part II 22
SUMMARY AND WRAP UP
Algorithms
Analysis
Asymptotic
NP-
Completeness
Design
D&C
DP
Greedy
Graph
B&B
Applications
Algorithms Divide and Conquer - Part II 23
WHERE WE ARE
 Strassen’s algorithm for matrix multiplication (Textbook § 4.8)
 Greedy Algorithms ((Textbook § 5.1 – 5.4)
 Section 4.2 in
http://compgeom.cs.uiuc.edu/~jeffe/teaching/algorithms/no
tes/04-greedy.pdf
Algorithms Divide and Conquer - Part II 24
READING ASSIGNMENTS

More Related Content

What's hot

Coin change Problem (DP & GREEDY)
Coin change Problem (DP & GREEDY)Coin change Problem (DP & GREEDY)
Coin change Problem (DP & GREEDY)Ridhima Chowdhury
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back trackingTech_MX
 
Data structures & problem solving unit 1 ppt
Data structures & problem solving unit 1 pptData structures & problem solving unit 1 ppt
Data structures & problem solving unit 1 pptaviban
 
5.2 divide and conquer
5.2 divide and conquer5.2 divide and conquer
5.2 divide and conquerKrish_ver2
 
Master method
Master method Master method
Master method Rajendran
 
Hashing Technique In Data Structures
Hashing Technique In Data StructuresHashing Technique In Data Structures
Hashing Technique In Data StructuresSHAKOOR AB
 
Peephole optimization techniques in compiler design
Peephole optimization techniques in compiler designPeephole optimization techniques in compiler design
Peephole optimization techniques in compiler designAnul Chaudhary
 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree methodRajendran
 
Principal source of optimization in compiler design
Principal source of optimization in compiler designPrincipal source of optimization in compiler design
Principal source of optimization in compiler designRajkumar R
 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURESbca2010
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notationsEhtisham Ali
 
Unix.system.calls
Unix.system.callsUnix.system.calls
Unix.system.callsGRajendra
 

What's hot (20)

Merge sort
Merge sortMerge sort
Merge sort
 
Coin change Problem (DP & GREEDY)
Coin change Problem (DP & GREEDY)Coin change Problem (DP & GREEDY)
Coin change Problem (DP & GREEDY)
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back tracking
 
Complexity analysis in Algorithms
Complexity analysis in AlgorithmsComplexity analysis in Algorithms
Complexity analysis in Algorithms
 
Data structures & problem solving unit 1 ppt
Data structures & problem solving unit 1 pptData structures & problem solving unit 1 ppt
Data structures & problem solving unit 1 ppt
 
5.2 divide and conquer
5.2 divide and conquer5.2 divide and conquer
5.2 divide and conquer
 
Bucket sort
Bucket sortBucket sort
Bucket sort
 
Master method
Master method Master method
Master method
 
Hashing Technique In Data Structures
Hashing Technique In Data StructuresHashing Technique In Data Structures
Hashing Technique In Data Structures
 
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
 
Peephole optimization techniques in compiler design
Peephole optimization techniques in compiler designPeephole optimization techniques in compiler design
Peephole optimization techniques in compiler design
 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree method
 
Principal source of optimization in compiler design
Principal source of optimization in compiler designPrincipal source of optimization in compiler design
Principal source of optimization in compiler design
 
Space complexity
Space complexitySpace complexity
Space complexity
 
Merge sort algorithm
Merge sort algorithmMerge sort algorithm
Merge sort algorithm
 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURES
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
push down automata
push down automatapush down automata
push down automata
 
Unix.system.calls
Unix.system.callsUnix.system.calls
Unix.system.calls
 
Time and Space Complexity
Time and Space ComplexityTime and Space Complexity
Time and Space Complexity
 

Viewers also liked

Introduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic NotationIntroduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic NotationAmrinder Arora
 
Graph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search TraversalGraph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search TraversalAmrinder Arora
 
Dynamic Programming - Part II
Dynamic Programming - Part IIDynamic Programming - Part II
Dynamic Programming - Part IIAmrinder Arora
 
Graph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First SearchGraph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First SearchAmrinder Arora
 
Dynamic Programming - Part 1
Dynamic Programming - Part 1Dynamic Programming - Part 1
Dynamic Programming - Part 1Amrinder Arora
 
Asymptotic Notation and Data Structures
Asymptotic Notation and Data StructuresAsymptotic Notation and Data Structures
Asymptotic Notation and Data StructuresAmrinder Arora
 
Euclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Euclid's Algorithm for Greatest Common Divisor - Time Complexity AnalysisEuclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Euclid's Algorithm for Greatest Common Divisor - Time Complexity AnalysisAmrinder Arora
 
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...Amrinder Arora
 
Dinive conquer algorithm
Dinive conquer algorithmDinive conquer algorithm
Dinive conquer algorithmMohd Arif
 
Divide and conquer - Quick sort
Divide and conquer - Quick sortDivide and conquer - Quick sort
Divide and conquer - Quick sortMadhu Bala
 
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)Amrinder Arora
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic NotationsRishabh Soni
 
CLOSEST PAIR (Final)
CLOSEST PAIR (Final)CLOSEST PAIR (Final)
CLOSEST PAIR (Final)Aruneel Das
 
BTrees - Great alternative to Red Black, AVL and other BSTs
BTrees - Great alternative to Red Black, AVL and other BSTsBTrees - Great alternative to Red Black, AVL and other BSTs
BTrees - Great alternative to Red Black, AVL and other BSTsAmrinder Arora
 

Viewers also liked (20)

Introduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic NotationIntroduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic Notation
 
Graph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search TraversalGraph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search Traversal
 
Dynamic Programming - Part II
Dynamic Programming - Part IIDynamic Programming - Part II
Dynamic Programming - Part II
 
Graph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First SearchGraph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First Search
 
NP completeness
NP completenessNP completeness
NP completeness
 
Dynamic Programming - Part 1
Dynamic Programming - Part 1Dynamic Programming - Part 1
Dynamic Programming - Part 1
 
Asymptotic Notation and Data Structures
Asymptotic Notation and Data StructuresAsymptotic Notation and Data Structures
Asymptotic Notation and Data Structures
 
Greedy Algorithms
Greedy AlgorithmsGreedy Algorithms
Greedy Algorithms
 
NP-Completeness - II
NP-Completeness - IINP-Completeness - II
NP-Completeness - II
 
Euclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Euclid's Algorithm for Greatest Common Divisor - Time Complexity AnalysisEuclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Euclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
 
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
 
Divide and Conquer
Divide and ConquerDivide and Conquer
Divide and Conquer
 
Dinive conquer algorithm
Dinive conquer algorithmDinive conquer algorithm
Dinive conquer algorithm
 
Divide and conquer - Quick sort
Divide and conquer - Quick sortDivide and conquer - Quick sort
Divide and conquer - Quick sort
 
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
 
Big o notation
Big o notationBig o notation
Big o notation
 
Algorithmic Puzzles
Algorithmic PuzzlesAlgorithmic Puzzles
Algorithmic Puzzles
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
 
CLOSEST PAIR (Final)
CLOSEST PAIR (Final)CLOSEST PAIR (Final)
CLOSEST PAIR (Final)
 
BTrees - Great alternative to Red Black, AVL and other BSTs
BTrees - Great alternative to Red Black, AVL and other BSTsBTrees - Great alternative to Red Black, AVL and other BSTs
BTrees - Great alternative to Red Black, AVL and other BSTs
 

Similar to Divide and Conquer - Part II - Quickselect and Closest Pair of Points

T2311 - Ch 4_Part1.pptx
T2311 - Ch 4_Part1.pptxT2311 - Ch 4_Part1.pptx
T2311 - Ch 4_Part1.pptxGadaFarhan
 
01 - DAA - PPT.pptx
01 - DAA - PPT.pptx01 - DAA - PPT.pptx
01 - DAA - PPT.pptxKokilaK25
 
Cs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer keyCs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer keyappasami
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03Krish_ver2
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03Krish_ver2
 
Sienna 4 divideandconquer
Sienna 4 divideandconquerSienna 4 divideandconquer
Sienna 4 divideandconquerchidabdu
 
module2_dIVIDEncONQUER_2022.pdf
module2_dIVIDEncONQUER_2022.pdfmodule2_dIVIDEncONQUER_2022.pdf
module2_dIVIDEncONQUER_2022.pdfShiwani Gupta
 
Matrix Multiplication(An example of concurrent programming)
Matrix Multiplication(An example of concurrent programming)Matrix Multiplication(An example of concurrent programming)
Matrix Multiplication(An example of concurrent programming)Pramit Kumar
 
Seminar Report (Final)
Seminar Report (Final)Seminar Report (Final)
Seminar Report (Final)Aruneel Das
 
HOME ASSIGNMENT (0).pptx
HOME ASSIGNMENT (0).pptxHOME ASSIGNMENT (0).pptx
HOME ASSIGNMENT (0).pptxSayedulHassan1
 
HOME ASSIGNMENT omar ali.pptx
HOME ASSIGNMENT omar ali.pptxHOME ASSIGNMENT omar ali.pptx
HOME ASSIGNMENT omar ali.pptxSayedulHassan1
 
dynamic programming complete by Mumtaz Ali (03154103173)
dynamic programming complete by Mumtaz Ali (03154103173)dynamic programming complete by Mumtaz Ali (03154103173)
dynamic programming complete by Mumtaz Ali (03154103173)Mumtaz Ali
 

Similar to Divide and Conquer - Part II - Quickselect and Closest Pair of Points (20)

Daa chapter 2
Daa chapter 2Daa chapter 2
Daa chapter 2
 
T2311 - Ch 4_Part1.pptx
T2311 - Ch 4_Part1.pptxT2311 - Ch 4_Part1.pptx
T2311 - Ch 4_Part1.pptx
 
02 Notes Divide and Conquer
02 Notes Divide and Conquer02 Notes Divide and Conquer
02 Notes Divide and Conquer
 
01 - DAA - PPT.pptx
01 - DAA - PPT.pptx01 - DAA - PPT.pptx
01 - DAA - PPT.pptx
 
Cs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer keyCs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer key
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03
 
Sienna 4 divideandconquer
Sienna 4 divideandconquerSienna 4 divideandconquer
Sienna 4 divideandconquer
 
Unit 2 in daa
Unit 2 in daaUnit 2 in daa
Unit 2 in daa
 
algorithm Unit 2
algorithm Unit 2 algorithm Unit 2
algorithm Unit 2
 
module2_dIVIDEncONQUER_2022.pdf
module2_dIVIDEncONQUER_2022.pdfmodule2_dIVIDEncONQUER_2022.pdf
module2_dIVIDEncONQUER_2022.pdf
 
Slide2
Slide2Slide2
Slide2
 
Divide and Conquer
Divide and ConquerDivide and Conquer
Divide and Conquer
 
Matrix Multiplication(An example of concurrent programming)
Matrix Multiplication(An example of concurrent programming)Matrix Multiplication(An example of concurrent programming)
Matrix Multiplication(An example of concurrent programming)
 
Seminar Report (Final)
Seminar Report (Final)Seminar Report (Final)
Seminar Report (Final)
 
HOME ASSIGNMENT (0).pptx
HOME ASSIGNMENT (0).pptxHOME ASSIGNMENT (0).pptx
HOME ASSIGNMENT (0).pptx
 
Unit 2
Unit 2Unit 2
Unit 2
 
HOME ASSIGNMENT omar ali.pptx
HOME ASSIGNMENT omar ali.pptxHOME ASSIGNMENT omar ali.pptx
HOME ASSIGNMENT omar ali.pptx
 
dynamic programming complete by Mumtaz Ali (03154103173)
dynamic programming complete by Mumtaz Ali (03154103173)dynamic programming complete by Mumtaz Ali (03154103173)
dynamic programming complete by Mumtaz Ali (03154103173)
 
algo_vc_lecture8.ppt
algo_vc_lecture8.pptalgo_vc_lecture8.ppt
algo_vc_lecture8.ppt
 

More from Amrinder Arora

Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...Amrinder Arora
 
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet MahanaArima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet MahanaAmrinder Arora
 
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...Amrinder Arora
 
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...Amrinder Arora
 
Online algorithms in Machine Learning
Online algorithms in Machine LearningOnline algorithms in Machine Learning
Online algorithms in Machine LearningAmrinder Arora
 
Set Operations - Union Find and Bloom Filters
Set Operations - Union Find and Bloom FiltersSet Operations - Union Find and Bloom Filters
Set Operations - Union Find and Bloom FiltersAmrinder Arora
 
Binomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci HeapsBinomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci HeapsAmrinder Arora
 
R-Trees and Geospatial Data Structures
R-Trees and Geospatial Data StructuresR-Trees and Geospatial Data Structures
R-Trees and Geospatial Data StructuresAmrinder Arora
 
Tries - Tree Based Structures for Strings
Tries - Tree Based Structures for StringsTries - Tree Based Structures for Strings
Tries - Tree Based Structures for StringsAmrinder Arora
 
Splay Trees and Self Organizing Data Structures
Splay Trees and Self Organizing Data StructuresSplay Trees and Self Organizing Data Structures
Splay Trees and Self Organizing Data StructuresAmrinder Arora
 
Binary Search Trees - AVL and Red Black
Binary Search Trees - AVL and Red BlackBinary Search Trees - AVL and Red Black
Binary Search Trees - AVL and Red BlackAmrinder Arora
 
Graphs, Trees, Paths and Their Representations
Graphs, Trees, Paths and Their RepresentationsGraphs, Trees, Paths and Their Representations
Graphs, Trees, Paths and Their RepresentationsAmrinder Arora
 
Stacks, Queues, Binary Search Trees - Lecture 1 - Advanced Data Structures
Stacks, Queues, Binary Search Trees -  Lecture 1 - Advanced Data StructuresStacks, Queues, Binary Search Trees -  Lecture 1 - Advanced Data Structures
Stacks, Queues, Binary Search Trees - Lecture 1 - Advanced Data StructuresAmrinder Arora
 
Online Algorithms - An Introduction
Online Algorithms - An IntroductionOnline Algorithms - An Introduction
Online Algorithms - An IntroductionAmrinder Arora
 

More from Amrinder Arora (15)

Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
 
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet MahanaArima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
 
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
 
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
 
Online algorithms in Machine Learning
Online algorithms in Machine LearningOnline algorithms in Machine Learning
Online algorithms in Machine Learning
 
Set Operations - Union Find and Bloom Filters
Set Operations - Union Find and Bloom FiltersSet Operations - Union Find and Bloom Filters
Set Operations - Union Find and Bloom Filters
 
Binomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci HeapsBinomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci Heaps
 
R-Trees and Geospatial Data Structures
R-Trees and Geospatial Data StructuresR-Trees and Geospatial Data Structures
R-Trees and Geospatial Data Structures
 
Tries - Tree Based Structures for Strings
Tries - Tree Based Structures for StringsTries - Tree Based Structures for Strings
Tries - Tree Based Structures for Strings
 
Splay Trees and Self Organizing Data Structures
Splay Trees and Self Organizing Data StructuresSplay Trees and Self Organizing Data Structures
Splay Trees and Self Organizing Data Structures
 
Binary Search Trees - AVL and Red Black
Binary Search Trees - AVL and Red BlackBinary Search Trees - AVL and Red Black
Binary Search Trees - AVL and Red Black
 
Graphs, Trees, Paths and Their Representations
Graphs, Trees, Paths and Their RepresentationsGraphs, Trees, Paths and Their Representations
Graphs, Trees, Paths and Their Representations
 
Stacks, Queues, Binary Search Trees - Lecture 1 - Advanced Data Structures
Stacks, Queues, Binary Search Trees -  Lecture 1 - Advanced Data StructuresStacks, Queues, Binary Search Trees -  Lecture 1 - Advanced Data Structures
Stacks, Queues, Binary Search Trees - Lecture 1 - Advanced Data Structures
 
Online Algorithms - An Introduction
Online Algorithms - An IntroductionOnline Algorithms - An Introduction
Online Algorithms - An Introduction
 
Learning to learn
Learning to learnLearning to learn
Learning to learn
 

Recently uploaded

Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 

Recently uploaded (20)

Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 

Divide and Conquer - Part II - Quickselect and Closest Pair of Points

  • 1. Design and Analysis of Algorithms DIVIDE AND CONQUER PART II CLOSEST PAIR OF POINTS MEDIAN FINDING SELECTION ALGORITHMS
  • 2.  Instructor Prof. Amrinder Arora amrinder@gwu.edu Please copy TA on emails Please feel free to call as well   Available for study sessions Science and Engineering Hall GWU Algorithms Divide and Conquer - Part II 2 LOGISTICS
  • 4.  A technique to solve complex problems by breaking into smaller instances of the problem and combining the results  Recursive methodology – Smaller instances of the same type of problem  Typically used with:  Principle of Mathematical Induction – For proving correctness  Recurrence relation solving – For computing time (and/or space) complexity Algorithms Divide and Conquer - Part II 4 DIVIDE AND CONQUER
  • 5.  Generalization step: Given an array and indexes i and j (start and end) to sort that portion of it  Algorithm MergeSort (input: A,i,j) { if input size is small, solve differently and return int k=(i+j)/2 MergeSort(A,i,k) MergeSort(A,k+1,j) Merge(A,i,k,k+1,j) } • T(n) = 2T(n/2) + n • T(n) = O(n log n) [Discussed in previous lectures.] Algorithms Divide and Conquer - Part II 5 MERGESORT
  • 6.  quicksort(A,p,r) if (p < r) { q = partition (A,p,r) quicksort(A,p,q-1) quicksort(A,q+1,r) } • Time complexity = ? [Discussed in previous lectures.] Algorithms Divide and Conquer - Part II 6 QUICKSORT
  • 7.  Given an array of unsorted numbers, how to find the median?  Option 1: Sort and return a[n/2]  That takes O(n log n) time. Is there a more efficient algorithm? Algorithms Divide and Conquer - Part II 7 MEDIAN FINDING
  • 8.  Step 1: Generalize the problem  Selection (A, k): Returns k-th smallest element in given array. For example:  Selection (A,1) = Smallest  Selection(A,n) = Largest // n is the array size.  Selection(A,n/2) = Median  Selection algorithms: http://en.wikipedia.org/wiki/Selection_algorithm  Also known as order statistic.  Generalization of largest, smallest, median, etc. problems.  This generalization step is very important for recursive calls! Algorithms Divide and Conquer - Part II 8 MEDIAN FINDING
  • 9. Selection (A,k) Partition the array A Suppose, the partition element lands at location k’ If (k == k’) { return x // Great, we really got lucky. } If (k < k’) { return Selection (A’,k) // Recursive call. Discard A” } If (k > k’) { return Selection (A”,k-k’) // Recursive call. Discard A’ } Algorithms Divide and Conquer - Part II 9 SELECTION – GENERAL TEMPLATE
  • 10.  The main complication (as in case of Quicksort) is to find a good partition. If the partition is very uneven, the algorithm may not be efficient.  We have two good choices:  Use probability to find a good partition by trying repeatedly  Find a good partition deterministically  In the coming few slides, we explore both of these methods. Algorithms Divide and Conquer - Part II 10 SELECTION – TWO APPROACHES
  • 11.  Partition randomly.  Define: A “good” partition is something that lands between the middle half, that is between ¼ and ¾ of the array.  You can find a “good” partition with probability ½  Expected number of times that you have to do a partition until you get a “good” partition = 2  Suppose the good partition “lands” at location k’, where n/4 <= k’ <= 3n/4  Depending upon value of k and k’, we make the appropriate recursive call, as specified in general template.  After partition, we remove at least 25% of the array.  T(n) <= 2n + T(0.75 n) // 2 reflects the expected # of times that we have to do the partition  T(n) <= cn // Using substitution method  Therefore, T(n) = O(n) Algorithms Divide and Conquer - Part II 11 SELECTION – PROBABILISTIC METHOD
  • 12.  Divide the array into groups of 5 (or 7)  Sort the small groups  Find the median of the medians  Partition the array on that median x x x x x ......... x x x x x x x x x x ......... x x x x x x x x x x ......... x x x x x x x x x x ......... x x x x x x x x x x ......... x x x x x Algorithms Divide and Conquer - Part II 12 SELECTION – QUICKSELECT ALGORITHM
  • 13.  Say x = the median of median  Then at least 30% of elements are <= x  At least 30% of elements are >= x  We use this x to be the partition element  Suppose x “lands” at location k’, where 3n/10 <= k’ <= 7n/10  Depending upon value of k and k’, we make the appropriate recursive call, as specified in general template.  Depending upon the value of k, either the left side of the partition or the right side will be discarded. In either case, we eliminate at least 30% of data.  We note that there are 2 recursive calls – 1st call to find the median of medians, and 2nd call after removing 25% of elements Algorithms Divide and Conquer - Part II 13 QUICKSELECT (CONT.)
  • 14.  T(n) = cn + T(n/5) + T(7n/10)  Proof that T(n) is linear, that is O(n), by substitution method (Using Principle of Mathematical Induction) We claim that T(n) <= 10 cn for all values of n < N T(N/5) <= 2cN T(7N/10) <= 7cN  T(N) <= cN + 2cN + 7cN = 10cN  The inequality holds for N  By principle of mathematical induction, inequality holds for all values of n.  Therefore, T(n) = O(n) Algorithms Divide and Conquer - Part II 14 QUICKSELECT – ANALYSIS
  • 15.  Given n points on the plane, find the closest pair of points.  http://en.wikipedia.org/wiki/Closest_pair_of_points_problem  Textbook section 4.7 Algorithms Divide and Conquer - Part II 15 DIVIDE AND CONQUER – ANOTHER APPLICATION
  • 16.  Naïve algorithm requires O(n2) time – simply compute all distances and find the minimum.  We are interested in a divide and conquer approach.  We remember that there is a signification difference between O(n2) time algorithm and O(n log n) time algorithm. For example, latter can easily be run with a trillion points, the O(n2) algorithm, not so much. Algorithms Divide and Conquer - Part II 16 CLOSEST PAIR OF POINTS
  • 17.  Divide and Conquer approach: 1. Split the set of points into two equal-sized subsets by finding the median of the x-dimensions of the points. 2. Solve the problem recursively for subsets to the left and right subsets. Thus, there are two recursive calls. 3. Find the minimal distance among the pair of points in which one point lies on the left of the dividing vertical and the second point lies to the right.  T(n) = cn + 2T(n/2) + f(n), where:  cn represents the time spent in Step 1 (linear time median finding)  2T(n/2) is time spent in two recursive calls in Step 2.  f(n) is the time spent in step 3, that is, time to find the minimum distance among the pairs, where one point lies to the left of the dividing vertical, and the second point lies to the right. Algorithms Divide and Conquer - Part II 17 CLOSEST PAIR OF POINTS (CONT.)
  • 18.  T(n) = 2T(n/2) + cn + f(n)  If f(n) = O(n2), then, T(n) = O(n2)  If f(n) = O(n), then T(n) = O(n log n)  Main complication then is to bound f(n)  If we can do f(n) in linear time, we will have an O(n log n) time algorithm.  In the next couple of slides, we discuss indeed how this can be done in linear time. Algorithms Divide and Conquer - Part II 18 CLOSEST PAIR OF POINTS (CONT.)
  • 19.  We define:  1 = Minimum distance found in the left side  2 = Minimum distance found in the right side   = Minimum of 1 and 2  Firstly, we are only interested in the points that are within a distance  of the dividing vertical.  For a point p1 on the left side of the dividing vertical, we are only interested in:  Points that are on the right side of the vertical, and within a distance  from the dividing vertical  Points that are within a vertical distance  from the point p1. Algorithms Divide and Conquer - Part II 19 CLOSEST PAIR OF POINTS (CONT.)
  • 20. Algorithms Divide and Conquer - Part II 20 CLOSEST PAIR OF POINTS (CONT.)
  • 21.  Thus for a point p1, there can only be 6 points of interest for that point.  Even if there are n/2 points to the left of the dividing vertical and within a distance , still that only means 3n pairs to consider  Therefore, f(n) = O(n)  Therefore, T(n) = 2T(n/2) + O(n)  Therefore, T(n) = O(n log n) Algorithms Divide and Conquer - Part II 21 CLOSEST PAIR OF POINTS (CONT.)
  • 22.  D&C – An interesting technique for solving problems  Three different ways to solve recurrence relations  Unfolding method  Substitution (guess and prove method)  Master Theorem – Another Method for solving Recurrence Relations  QuickSelect – O(n) time algorithm for selecting k-th largest element in an unsorted array.  The constant is rather large, use this algorithm with caution  Closest pair of points – An interesting O(n log n) time recursive algorithm for finding the closest pair of points. Algorithms Divide and Conquer - Part II 22 SUMMARY AND WRAP UP
  • 24.  Strassen’s algorithm for matrix multiplication (Textbook § 4.8)  Greedy Algorithms ((Textbook § 5.1 – 5.4)  Section 4.2 in http://compgeom.cs.uiuc.edu/~jeffe/teaching/algorithms/no tes/04-greedy.pdf Algorithms Divide and Conquer - Part II 24 READING ASSIGNMENTS