Lecture 4. The Substitution Method and Median and Selection

Similar documents
Lecture 4 Median and Selection

1 Introduction. 2 InsertionSort. 2.1 Correctness of InsertionSort

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Sorting lower bound and Linear-time sorting Date: 9/19/17

Lecture 6. Binary Search Trees and Red-Black Trees

Introduction to Algorithms

Selection (deterministic & randomized): finding the median in linear time

Lecture 14. Greedy algorithms!

CS125 : Introduction to Computer Science. Lecture Notes #38 and #39 Quicksort. c 2005, 2003, 2002, 2000 Jason Zych

Scribe: Sam Keller (2015), Seth Hildick-Smith (2016), G. Valiant (2017) Date: January 25, 2017

The divide and conquer strategy has three basic parts. For a given problem of size n,

COMP Analysis of Algorithms & Data Structures

Lecture 7. Binary Search Trees and Red-Black Trees

The Substitution method

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.

CSE 332: Data Structures & Parallelism Lecture 12: Comparison Sorting. Ruth Anderson Winter 2019

1 Probabilistic analysis and randomized algorithms

MergeSort, Recurrences, Asymptotic Analysis Scribe: Michael P. Kim Date: April 1, 2015

Lecture #2. 1 Overview. 2 Worst-Case Analysis vs. Average Case Analysis. 3 Divide-and-Conquer Design Paradigm. 4 Quicksort. 4.

Lecture 9: Sorting Algorithms

MergeSort, Recurrences, Asymptotic Analysis Scribe: Michael P. Kim Date: September 28, 2016 Edited by Ofir Geri

Mergesort again. 1. Split the list into two equal parts

CS2223: Algorithms Sorting Algorithms, Heap Sort, Linear-time sort, Median and Order Statistics

CS 171: Introduction to Computer Science II. Quicksort

Sorting is a problem for which we can prove a non-trivial lower bound.

COSC242 Lecture 7 Mergesort and Quicksort

(Refer Slide Time: 01.26)

Lecture 2: Divide&Conquer Paradigm, Merge sort and Quicksort

Principles of Algorithm Design

Information Coding / Computer Graphics, ISY, LiTH

CS 4349 Lecture August 21st, 2017

CSE373: Data Structure & Algorithms Lecture 21: More Comparison Sorting. Aaron Bauer Winter 2014

Algorithms and Data Structures (INF1) Lecture 7/15 Hua Lu

Randomized Algorithms, Quicksort and Randomized Selection

CS125 : Introduction to Computer Science. Lecture Notes #40 Advanced Sorting Analysis. c 2005, 2004 Jason Zych

Quicksort (CLRS 7) We saw the divide-and-conquer technique at work resulting in Mergesort. Mergesort summary:

Randomized Algorithms: Selection

CPSC 311 Lecture Notes. Sorting and Order Statistics (Chapters 6-9)

EECS 2011M: Fundamentals of Data Structures

Algorithms and Data Structures: Lower Bounds for Sorting. ADS: lect 7 slide 1

CSE 373: Data Structures and Algorithms

CS 137 Part 8. Merge Sort, Quick Sort, Binary Search. November 20th, 2017

Sorting & Growth of Functions

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

Quicksort (Weiss chapter 8.6)

Lecture 15 : Review DRAFT

CS S-11 Sorting in Θ(nlgn) 1. Base Case: A list of length 1 or length 0 is already sorted. Recursive Case:

Sorting. Dr. Baldassano Yu s Elite Education

4. Sorting and Order-Statistics

Comparison Based Sorting Algorithms. Algorithms and Data Structures: Lower Bounds for Sorting. Comparison Based Sorting Algorithms

CSE 373: Data Structures and Algorithms

Analysis of Algorithms - Medians and order statistic -

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

CSC236 Week 5. Larry Zhang

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Approximation algorithms Date: 11/27/18

Introduction to Algorithms / Algorithms I Lecturer: Michael Dinitz Topic: Approximation algorithms Date: 11/18/14

Analysis of Algorithms - Quicksort -

CSE373: Data Structure & Algorithms Lecture 18: Comparison Sorting. Dan Grossman Fall 2013

Lecture 8: Mergesort / Quicksort Steven Skiena

cmpt-225 Sorting Part two

Lecture 2: Divide and Conquer

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

Lecture 10. Finding strongly connected components

Quick Sort. CSE Data Structures May 15, 2002

Divide and Conquer Sorting Algorithms and Noncomparison-based

Algorithms and Data Structures

Parallel and Sequential Data Structures and Algorithms Lecture (Spring 2012) Lecture 16 Treaps; Augmented BSTs

Searching, Sorting. part 1

Notes slides from before lecture. CSE 21, Winter 2017, Section A00. Lecture 9 Notes. Class URL:

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

08 A: Sorting III. CS1102S: Data Structures and Algorithms. Martin Henz. March 10, Generated on Tuesday 9 th March, 2010, 09:58

CS 171: Introduction to Computer Science II. Quicksort

II (Sorting and) Order Statistics

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

COMP 250 Fall recurrences 2 Oct. 13, 2017

Introduction to Algorithms / Algorithms I Lecturer: Michael Dinitz Topic: Shortest Paths Date: 10/13/15

COT 5407: Introduction to Algorithms. Giri Narasimhan. ECS 254A; Phone: x3748

7. Sorting I. 7.1 Simple Sorting. Problem. Algorithm: IsSorted(A) 1 i j n. Simple Sorting

Programming II (CS300)

CS 4349 Lecture October 18th, 2017

Divide and Conquer Algorithms

Treaps. 1 Binary Search Trees (BSTs) CSE341T/CSE549T 11/05/2014. Lecture 19

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

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

Algorithms and Data Structures for Mathematicians

We will give examples for each of the following commonly used algorithm design techniques:

15-451/651: Design & Analysis of Algorithms November 4, 2015 Lecture #18 last changed: November 22, 2015

DIVIDE & CONQUER. Problem of size n. Solution to sub problem 1

Sorting: Given a list A with n elements possessing a total order, return a list with the same elements in non-decreasing order.

Randomized Algorithms, Hash Functions

CSC 505, Spring 2005 Week 6 Lectures page 1 of 9

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

Scan and Quicksort. 1 Scan. 1.1 Contraction CSE341T 09/20/2017. Lecture 7

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

Intro to Algorithms. Professor Kevin Gold

Quicksort. Alternative Strategies for Dividing Lists. Fundamentals of Computer Science I (CS F)

Divide-and-Conquer. Dr. Yingwu Zhu

(Refer Slide Time 04:53)

Jana Kosecka. Linear Time Sorting, Median, Order Statistics. Many slides here are based on E. Demaine, D. Luebke slides

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

Sorting. Sorting in Arrays. SelectionSort. SelectionSort. Binary search works great, but how do we create a sorted array in the first place?

Transcription:

Lecture 4 The Substitution Method and Median and Selection

Announcements! HW1 due Friday. (And HW2 also posted Friday).

Last Time: The Master Theorem Suppose T n =a T & ' +O n*. Then Three parameters: a : number of subproblems b : factor by which input size shrinks d : need to do n d work to create all the subproblemsand combine their solutions. A powerful theorem it is Jedi master Yoda

Today more recursion, beyond the Master Theorem. The Master Theorem only works when all sub-problems are the same size. That s not always the case. Today we ll see an example where the Master Theorem won t work. We ll use something called the substitution method instead. I can handle all the recurrence relations that looklike T n =a T & ' +O n*. Before this theorem I was but the learner. Now I am the master. Only a master of evil*, Darth. *More precisely, only a master of same-size sub-problems still pretty handy, actually.

The Plan 1. The Substitution Method You got a sneak peak on your pre-lecture exercise 2. The SELECTproblem. 3. The SELECTsolution. 4. Return of the Substitution Method.

A non-tree method Here s another way to solve: For most of this lecture, division is integer division: &, means &,. As we noted last time we ll be pretty sloppy about the difference. T n =2 T &, +n T 0 =0, T 1 =1 1. Guess what the answer is. 2. Formally prove that that s what the answer is. You did this for your pre-lecture exercise! Let s go through it now quickly to make sure we are all on the same page.

1. Guess what the answer is. T n =2 T &, +n T n =2 2 T & 6 +&, +n T n =4 T & 6 +2 n T n =4 2 T & 8 +& 6 +2 n T n =8 T & 8 +3 n Following the pattern T n =n T 1 +log n n=n(log n +1 ) So that is our guess!

Inductive hypothesis: T k k(log k +1 )for all 1 k n Base case: T 1 =1=1(log 1 +1 ) Inductive step: T n =2 T &, +n 2 &, log &, +1 +n 2. Prove our guess is right We ll go fast through these computations because you all did it on your pre-lecture exercise! What happened between these two lines? =2 &, log n 1+1 +n =2 &, log n +n =n(log n +1 ) Conclusion: By induction, T n =n(log n +1 )for all n > 0.

That s called the substitution method So far, just seems like a different way of doing the same thing. But consider this! T n =3n+T n 5 +T n 2 T n = 10n when 1 n 10

Gross! Step 1: guess what the answer is T n =3n+T n 5 +T n 2 T n = 10n when 1 n 10 Let s try the same unwinding thing to get a feel for it. [On board] Okay, that gets gross fast. We can also just try it out. [IPythonNotebook] What else do we know?: T n 3n+T & P +T &, 3n+2 T &, =O(nlog n ) T n 3n So the right answer is somewhere between O(n) and O(nlog(n))

Let s guess O(n) Step 2: prove our guess is right T n =3n+T n 5 +T n 2 T n = 10n when 1 n 10 Inductive Hypothesis: T k Ckfor all 1 k< n. Base case: T k Ckfor all k 10 Inductive step: T n =3n+T & P +T &, Conclusion: 3n+C & P +C &, =3n+ C P n+c, n Cn?? Let s solve for C and make this true! C = 10 works. (on board) There is some Cso that for all n 1,T n Cn Aka, T(n) = O(n). C is some constant we ll have to fill in later! Whatever we choose C to be, it should have C 10

Now pretend like we knew it all along. T n =3n+T n 5 +T n 2 T n = 10n when 1 n 10 Theorem: T n =O n Proof: Inductive Hypothesis: T k 10kfor all k < n. Base case: T k 10kfor all k 10 Inductive step: T n =3n+T & P +T &, T n 3n+10 & P +10 &, T n 3n+2n+5n=10n. Conclusion: For all n 1,T n 10n, aka T(n) = O(n).

What have we learned? The substitution method can work when the master theorem doesn t. For example with different-sized sub-problems. Step 1: generate a guess Throw the kitchen sink at it. Step 2: try to prove that your guess is correct You may have to leave some constants unspecified till the end then see what they need to be for the proof to work!! Step 3: profit Pretend you didn t do Steps 1 and 2 and write down a nice proof.

The Plan 1. The Substitution Method You got a sneak peak on your pre-lecture exercise 2. The SELECTproblem. 3. The SELECTsolution. 4. Return of the Substitution Method.

The problem we will solve A is an array of size n, k is in {1,,n} SELECT(A, k): Return the k thsmallest element of A. 7 4 3 8 1 5 9 14 SELECT(A, 1) = 1 SELECT(A, 2) = 3 SELECT(A, 3) = 4 SELECT(A, 8) = 14 SELECT(A, 1) = MIN(A) SELECT(A, n/2) = MEDIAN(A) SELECT(A, n) = MAX(A) Being sloppy about floors and ceilings! Note that the definition of Select is 1-indexed

We re gonnado it in time O(n) Let s start with MIN(A) aka SELECT(A, 1). MIN(A): ret = Fori=0,..., n-1: If A[i] < ret: ret = A[i] Returnret Time O(n). Yay! This stuff is O(1) This loop runs O(n) times

How about SELECT(A,2)? SELECT2(A): ret = minsofar = Fori=0,.., n-1: IfA[i] < ret and A[i] < minsofar: ret = minsofar minsofar= A[i] Elseif A[i] < ret and A[i] >= minsofar: ret = A[i] Returnret (The actual algorithm here is not very important because this won t end up being a very good idea ) Still O(n) SO FAR SO GOOD.

SELECT(A, n/2) aka MEDIAN(A)? MEDIAN(A): ret = minsofar = secondminsofar= thirdminsofar= fourthminsofar=. This is not a good idea for large k (like n/2 or n). Basically this is just going to turn into something like INSERTIONSORT and that was O(n 2 ).

A much better idea for large k SELECT(A, k): A = MergeSort(A) return A[k-1] It s k-1 and not k since my pseudocode is 0-indexed and the problem is 1-indexed Running time is O(n log(n)). So that s the benchmark. Can we do better? We re hoping to get O(n) Show that you can t do better than O(n)! (Or see lecture notes).

The Plan 1. The Substitution Method You got a sneak peak on your pre-lecture exercise 2. The SELECTproblem. 3. The SELECTsolution. 4. Return of the Substitution Method.

Idea: divide and conquer! Say we want to find SELECT(A, k) 9 8 3 6 1 4 2 First, pick a pivot. We ll see how to do this later. Next, partition the array into bigger than 6 or less than 6 How about this pivot? This PARTITION step takes time O(n). (Notice that we don t sort each half). L = array with things smaller than A[pivot] R = array with things larger than A[pivot]

Idea: divide and conquer! Say we want to find SELECT(A, k) 6 First, pick a pivot. We ll see how to do this later. Next, partition the array into bigger than 6 or less than 6 How about this pivot? This PARTITION step takes time O(n). (Notice that we don t sort each half). 3 1 4 2 9 8 L = array with things smaller than A[pivot] R = array with things larger than A[pivot]

Idea continued Say we want to find SELECT(A, k) 3 1 4 2 L = array with things smaller than A[pivot] 6 pivot 9 8 R = array with things larger than A[pivot] If k = 5 = len(l) + 1: We should return A[pivot] If k < 5: We should return SELECT(L, k) If k > 5: We should return SELECT(R, k 5) This suggests a recursive algorithm (still need to figure out how to pick the pivot )

Pseudocode getpivot(a)returns some pivot for us. How?? We ll see later Partition(A,p)splits up A into L, A[p], R. See Lecture 4 notebook for code Select(A,k): Iflen(A) <= 50: A = MergeSort(A) ReturnA[k-1] p = getpivot(a) L, pivotval, R = Partition(A,p) iflen(l) == k-1: return pivotval Else if len(l) > k-1: return Select(L, k) Else if len(l) < k-1: return Select(R, k len(l) 1) Base Case: If the len(a) = O(1), then any sorting algorithm runs in time O(1). Case 1: We got lucky and found exactly the k th smallest value! Case 2: The k thsmallest value is in the first part of the list Case 3: The k thsmallest value is in the second part of the list

Let s make sure it works [IPythonNotebook for Lecture 4]

Now we should be convinced No matter what procedure we use for getpivot(a), Select(A,k) returns a correct answer. Formally prove the correctness of Select! Siggi the Studious Stork

What is the running time? T n = T len L +O n len L >k 1 T len R +O n len L <k 1 O n len L =k 1 What are len(l)and len(r)? That depends on how we pick the pivot What do we hope happens? What do we hope doesn t happen?

In an ideal world* We split the input in half: len(l) = len(r) = (n-1)/2 Apply here, the Master Theorem does NOT. Making unsubstantiated assumptions about problem sizes, we are. Let s use the Master Theorem! T n T &, +O(n) So a = 1, b = 2, d = 1 T n O n * =O n Jedi master Yoda Suppose T n =a T & ' +O n*. Then *Okay, really ideal would be that we always pick the pivot so that len(l) = k-1. But say we don t have control over k, just over how we pick the pivot.

But the world is not ideal. Suppose we choose a pivot first, but thena bad guy who knows what pivots we will choosegets to come up with A. [Discussion on board]

The distinction matters! For this one I chose the worst possible pivot. Looks like O(n 2 ). This one is a random pivot, so it splits the array about in half. Looks pretty fast! See Lecture 4 IPythonnotebook for code that generated this picture.

Question How do we pick a good pivot? Randomly? That works well if there s no bad guy. But if there is a bad guy who gets to see our pivot choices, that s just as bad as the worst-case pivot. Aside: In practice, there is often no bad guy. In that case, just pick a random pivot and it works really well! (More on this next week)

But for today Let s assume there s this bad guy. We ll get a stronger guarantee We ll get to see a really clever algorithm And we ll get more practice with the substitution method.

The Plan 1. The Substitution Method You got a sneak peak on your pre-lecture exercise 2. The SELECTproblem. 3. The SELECTsolution. a) The outline of the algorithm. b) How to pick the pivot. 4. Return of the Substitution Method.

How should we pick the pivot? We d like to live in the ideal world. Pick the pivot to divide the input in half! Aka, pick the median! Aka, pick Select(A,n/2)

How should we pick the pivot? We d like to approximatethe ideal world. Pick the pivot to divide the input aboutin half! Maybe this is easier!

okay In an ideal world Apply here, the Master Theorem STILL does NOT. (Since we don t know that we can do this and if we could how long would it take?). We split the input not quite in half: 3n/10 < len(l) < 7n/10 3n/10 < len(r) < 7n/10 If we could do that, the Master Theoremwould say: T n T ]& ^_ +O(n) So a = 1, b = 10/7, d = 1 T n O n * =O n But at least it gives us a goal! Jedi master Yoda Lucky the lackadaisical lemur Suppose T n =a T & ' +O n*. Then

Goal Pick the pivot so that 6 3 1 4 2 pivot 9 8 L = array with things smaller than A[pivot] R = array with things larger than A[pivot] 3n 10 < len L <7n 10 3n 10 < len R <7n 10

*we will make this a bit more precise. Another divide-and-conquer alg! We can t solve Select(A,n/2) (yet) But we can divide and conquer and solve Select(B,m/2)for smaller values of m (where len(b) = m). Lemma*: The median of sub-medians is close to the median. What we ll use as the pivot median of sub-medians median of the whole thing Ideal pivot sub-median sub-median sub-median sub-median sub-median

How to pick the pivot CHOOSEPIVOT(A): Split A into m = & groups, of size <=5 each. P Fori=1,.., m: Find the median within the i thgroup, call it p i p =SELECT( [ p 1, p 2, p 3,, p m ], m/2) returnp 8 4 This takes time O(1), for each group, since each group has size 5. So that s O(m) total in the for loop. 1 8 9 3 15 5 9 1 3 4 12 2 1 5 20 15 13 2 4 6 12 1 15 22 3 Pivot is SELECT( 8 4 5 6 12, 3 ) = 6: 1 8 9 3 15 5 9 1 3 4 12 2 1 5 20 15 13 2 4 6 6 12 12 1 15 22 3 PARTITION around that 6: 6 1 3 5 1 3 4 2 1 2 4 1 3 5 8 9 15 9 12 20 15 13 12 15 22 This part is L This part is R: it s almost the same size as L.

CLAIM: this works divides the array approximatelyin half Empirically (see Lecture 4 IPythonNotebook):

CLAIM: this works divides the array approximatelyin half Formally, we will prove (later): Lemma: If we choose the pivots like this, then L 7n 10 +5 and R 7n 10 +5

Sanity Check L ]& ^_ +5 and R ]& ^_ +5 Actually in practice (on randomly chosen arrays) it looks even better! But this is a worstcast bound. That s this window

How about the running time? Suppose the Lemma is true. (It is). L ]& ^_ +5 and R ]& ^_ +5 Recurrence relation: T n?

Pseudocode getpivot(a)returns some pivot for us. How?? We ll see later Partition(A,p)splits up A into L, A[p], R. See Lecture 4 notebook for code Select(A,k): Iflen(A) <= 50: A = MergeSort(A) ReturnA[k-1] p = getpivot(a) L, pivotval, R = Partition(A,p) iflen(l) == k-1: return pivotval Else if len(l) > k-1: return Select(L, k) Else if len(l) < k-1: return Select(R, k len(l) 1) Base Case: If the len(a) = O(1), then any sorting algorithm runs in time O(1). Case 1: We got lucky and found exactly the k th smallest value! Case 2: The k thsmallest value is in the first part of the list Case 3: The k thsmallest value is in the second part of the list

How about the running time? Suppose the Lemma is true. (It is). L ]& ^_ +5 and R ]& ^_ +5 Recurrence relation: T n T & P +T ]& ^_ +O n

The Plan 1. The Substitution Method You got a sneak peak on your pre-lecture exercise 2. The SELECTproblem. 3. The SELECTsolution. a) The outline of the algorithm. b) How to pick the pivot. 4. Return of the Substitution Method.

This sounds like a job for [On board] T n T & P +T ]& ^_ +O n Step 1: generate a guess Step 2: try to prove that your guess is correct Step 3: profit Like we did last time, treat this O(n) as cnfor our analysis. (For simplicity in class to be rigorous we should use the formal definition!) Conclusion: T n =O n

In practice? With my dumb implementation, our fancy version of Selectis worse than MergeSort-based Select. L But O(n) is better than O(nlog(n))! How can that be? What s the constant in front of the n in our proof? 20? 30? On non-adversarial inputs, random pivot choice is MUCHbetter. Optimize the implementation of Select(with the fancy pivot). Can you beat MergeSort? Siggithe Studious Stork

What have we learned? Pending the Lemma It is possible to solve SELECT in time O(n). Divide and conquer! If you expect that a bad guy* will be picking the list, choose a pivot cleverly. More divide and conquer! If you don t expect that a bad guy* will be picking the list, in practice it s better just to pick a random pivot. *A bad guy who knows your pivot choices ahead of time.

The Plan 1. The Substitution Method You got a sneak peak on your pre-lecture exercise 2. The SELECTproblem. 3. The SELECTsolution. a) The outline of the algorithm. b) How to pick the pivot. 4. Return of the Substitution Method. 5. (If time) Proof of that lemma.

If time, back to the Lemma Lemma: If L and R are as in the algorithm SELECT given above, then L 7n 10 +5 and R 7n 10 +5 We will see a proof by picture. See CLRS for proof by proof.

Proof by picture 1 5 2 3 6 8 18 10 13 7 5 9 4 7 70 17 3 6 12 4 22 15 35 11 2 m Say these are our m = [n/5] sub-arrays of size at most 5.

Proof by picture 1 4 2 2 6 3 5 7 3 7 5 8 6 10 4 17 9 18 11 13 22 15 35 12 70 In our head, let s sort them. Then find medians. m

Proof by picture 2 4 1 2 3 5 6 3 7 5 4 6 7 8 10 13 18 17 9 11 70 35 22 15 12 m Then let s sort them by the median

Proof by picture 2 4 1 2 3 5 6 3 7 5 4 6 7 8 10 13 18 17 9 11 70 35 22 15 12 m The median of the medians is 7. That s our pivot!

Proof by picture We will show that lots of elements are smaller than the pivot, hence not too many are larger than the pivot. 2 4 1 2 3 5 6 3 7 5 4 6 7 8 10 13 18 17 9 11 70 35 22 15 12 m How many elements are SMALLER than the pivot?

Proof by picture 2 4 1 2 3 5 6 3 7 5 4 6 7 8 10 13 18 17 9 11 70 35 22 15 12 m At least these ones: everything above and to the left.

Proof by picture 3 j, 1 of these, but then one of them could have been the leftovers group. 2 4 1 2 3 5 6 3 7 5 4 6 7 8 10 13 18 17 9 11 70 35 22 15 12 How many of those are there? at least 3 j, 2 m

Proof by picture 2 4 1 2 3 5 6 3 7 5 4 6 7 8 10 13 18 17 9 11 70 35 22 15 12 m So how many are LARGER than the pivot? At most (derivation on board) n 1 3 m 2 2 7n 10 +5 Remember m= n 5

That was one part of the lemma Lemma: If L and R are as in the algorithm SELECT given above, then L 7n 10 +5 and R 7n 10 +5 The other part is exactly the same.

The Plan 1. The Substitution Method You got a sneak peak on your pre-lecture exercise 2. The SELECTproblem. 3. The SELECTsolution. a) The outline of the algorithm. b) How to pick the pivot. 4. Return of the Substitution Method. Recap

Recap The substitution method is another way to solve recurrence relations. Can work when the master theorem doesn t! One place we needed it was for SELECT. Which we can do in time O(n)!

Next time Randomized algorithms and QuickSort! BEFOREnext time Pre-Lecture Exercise 5 Remember probability theory? The pre-lecture exercise will jog your memory.