CS 2110: INDUCTION DISCUSSION TOPICS

Similar documents
Solving Recurrences. Lecture 23 CS2110 Fall 2011

Asymptotic Running Time of Algorithms

Analysis of Algorithms - Using Asymptotic Bounds -

Lecture 17: Trees and Merge Sort 10:00 AM, Oct 15, 2018

b + O(n d ) where a 1, b > 1, then O(n d log n) if a = b d d ) if a < b d O(n log b a ) if a > b d

What we have learned What is algorithm Why study algorithm The time and space efficiency of algorithm The analysis framework of time efficiency Asympt

Recursion: Introduction and Correctness

Divide and Conquer CPE 349. Theresa Migler-VonDollen

CS 4104 Data and Algorithm Analysis. Recurrence Relations. Modeling Recursive Function Cost. Solving Recurrences. Clifford A. Shaffer.

Algorithm Analysis Recurrence Relation. Chung-Ang University, Jaesung Lee

Binomial Coefficient Identities/Complements

CS1800: Mathematical Induction. Professor Kevin Gold

Design and Analysis of Algorithms

COMP Analysis of Algorithms & Data Structures

COMP Analysis of Algorithms & Data Structures

Induction. Announcements. Overview. Defining Functions. Sum of Squares. Closed-form expression for SQ(n) There have been some corrections to A1

CSE101: Design and Analysis of Algorithms. Ragesh Jaiswal, CSE, UCSD

CS 4349 Lecture August 30th, 2017

CS 310 Advanced Data Structures and Algorithms

Divide and Conquer Algorithms. CSE 101: Design and Analysis of Algorithms Lecture 14

Asymptotic Analysis and Recurrences

Selection and Adversary Arguments. COMP 215 Lecture 19

Review Of Topics. Review: Induction

1 Divide and Conquer (September 3)

MA008/MIIZ01 Design and Analysis of Algorithms Lecture Notes 3

Mergesort and Recurrences (CLRS 2.3, 4.4)

Divide and Conquer. CSE21 Winter 2017, Day 9 (B00), Day 6 (A00) January 30,

ITEC2620 Introduction to Data Structures

Divide and Conquer. Recurrence Relations

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Asymptotic Analysis, recurrences Date: 9/7/17

CIS 121. Analysis of Algorithms & Computational Complexity. Slides based on materials provided by Mary Wootters (Stanford University)

Sum of Squares. Defining Functions. Closed-Form Expression for SQ(n)

Linear Time Selection

When we use asymptotic notation within an expression, the asymptotic notation is shorthand for an unspecified function satisfying the relation:

Methods for solving recurrences

General Comments Proofs by Mathematical Induction

CS483 Design and Analysis of Algorithms

Advanced Counting Techniques. Chapter 8

5 + 9(10) + 3(100) + 0(1000) + 2(10000) =

Mathematical Induction

When we use asymptotic notation within an expression, the asymptotic notation is shorthand for an unspecified function satisfying the relation:

Divide and Conquer. Andreas Klappenecker

Solving Recurrences. 1. Express the running time (or use of some other resource) as a recurrence.

data structures and algorithms lecture 2

CS 4407 Algorithms Lecture 2: Iterative and Divide and Conquer Algorithms

#29: Logarithm review May 16, 2009

Quick Sort Notes , Spring 2010

Recurrences COMP 215

Divide and Conquer. Andreas Klappenecker. [based on slides by Prof. Welch]

General Comments on Proofs by Mathematical Induction

Data Structures and Algorithms CMPSC 465

Mathematical Induction

Grade 11/12 Math Circles Fall Nov. 5 Recurrences, Part 2

In-Class Soln 1. CS 361, Lecture 4. Today s Outline. In-Class Soln 2

1 Terminology and setup

Lecture 3. Big-O notation, more recurrences!!

Lecture 1: Asymptotics, Recurrences, Elementary Sorting

CSC236 Week 4. Larry Zhang

Algorithms and Data Structures 2016 Week 5 solutions (Tues 9th - Fri 12th February)

Quiz 3 Reminder and Midterm Results

Algorithm Design and Analysis

CS 4407 Algorithms Lecture 3: Iterative and Divide and Conquer Algorithms

1 Closest Pair of Points on the Plane

Solving Recurrences. 1. Express the running time (or use of some other resource) as a recurrence.

The Inductive Proof Template

The maximum-subarray problem. Given an array of integers, find a contiguous subarray with the maximum sum. Very naïve algorithm:

Computational Complexity. This lecture. Notes. Lecture 02 - Basic Complexity Analysis. Tom Kelsey & Susmit Sarkar. Notes

CS173 Running Time and Big-O. Tandy Warnow

CS 577 Introduction to Algorithms: Strassen s Algorithm and the Master Theorem

1 Recursive Algorithms

CPS 616 DIVIDE-AND-CONQUER 6-1

A design paradigm. Divide and conquer: (When) does decomposing a problem into smaller parts help? 09/09/ EECS 3101

V. Adamchik 1. Recurrences. Victor Adamchik Fall of 2005

Advanced Counting Techniques

Design and Analysis of Algorithms

Algorithms Design & Analysis. Analysis of Algorithm

Week 5: Quicksort, Lower bound, Greedy

Notes for Recitation 14

Algorithms. Quicksort. Slide credit: David Luebke (Virginia)

CS483 Design and Analysis of Algorithms

Concrete models and tight upper/lower bounds

CSC 344 Algorithms and Complexity. Proof by Mathematical Induction

Introduction to Divide and Conquer

CS 361, Lecture 14. Outline

Analysis of Algorithms I: Asymptotic Notation, Induction, and MergeSort

Fall 2017 Test II review problems

Solving recurrences. Frequently showing up when analysing divide&conquer algorithms or, more generally, recursive algorithms.

CMPT 307 : Divide-and-Conqer (Study Guide) Should be read in conjunction with the text June 2, 2015

Lecture 2. More Algorithm Analysis, Math and MCSS By: Sarah Buchanan

SYDE 112, LECTURE 7: Integration by Parts

Divide and Conquer Algorithms

Analysis of Algorithms

CS Data Structures and Algorithm Analysis

Algorithm efficiency can be measured in terms of: Time Space Other resources such as processors, network packets, etc.

Problem Set 1. CSE 373 Spring Out: February 9, 2016

Fall 2017 November 10, Written Homework 5

CSC236 Intro. to the Theory of Computation Lecture 7: Master Theorem; more D&C; correctness

Asymptotic Algorithm Analysis & Sorting

UCSD CSE 21, Spring 2014 [Section B00] Mathematics for Algorithm and System Analysis

Recursion and Induction

Transcription:

CS 110: INDUCTION DISCUSSION TOPICS The following ideas are suggestions for how to handle your discussion classes. You can do as much or as little of this as you want. You can either present at the board, or you can have students work on the problems. You all know your discussion sections better than I do. The goal of this document is to give you some ideas of what to cover and how to present it, in order to be consistent with the lecture. With that said, as a bare minimum, I suggest that you cover one of the weak induction proofs (such as Example??) and the MergeSort recurrence. Weak Induction Proofs The primary goal of discussion is to give students practice with induction. In order to be consistent with the lecture, I highly recommend that you use the following style: At the start, identify the inductive strategy needed to solve the problem. This is a recursive function or algorithm that will make induction easier. Sometimes it is given, but sometimes the student has to come up with it. This is covered in the lecture, but I have an example of it below. Once the strategy is defined, write up in a highly structured format. Clearly identify the base step, the inductive hypothesis and the inductive step. Again, I have an example of this below. The idea is that the inductive strategy is what they do on scrap paper, but a proof needs to be clearly written up. The motivation of induction for this class is recurrence relations, so some of the best examples to use are the classic summation identities. Here are some classic ones to use. Pick whichever ones you like best: Example 1. Let (1) S(n) = 0 + 1 + +... + n = () S(n) = for all n 0. n(n + 1)(n + 1) 6 i Example. Let (3) S(n) = 1 + 3 + 5 +... + (n + 1) = (i + 1) 1

DISCUSSION TOPICS (4) S(n) = for all n 0. (n + 1)(n + 1)(n + 3) 3 Example 3. Let (5) S(n) = 0 0 + 1 1 + +... + n n = (6) S(n) = (n 1) n+1 + i i As an demonstration, let s do Example 3. In order to do induction, we need a recursive function involved. We suspect that we can write the function in (5) as the recursive function { 0 if n = 0 S R (n) = S R (n 1) + n n if n > 0 However, this is just our strategy. We have not proven this yet. That means that what we really want to prove now is (7) S(n) = S R (n) = (n 1) n+1 + That is, we now have three different things: the iterative function on the left, the recursive function in the middle, and the closed form expression on the right. We want to prove that all three are equal. Write (7) up as claim, and then proceed with the induction proof. Clearly label the following three steps: Base Step: We prove the claim for n = 0. Clearly S(0) = 0 and S R (0) = 0. Furthermore, (0 1) 0+1 + = + = 0 Therefore, all three are equal and we are done with the base step. Inductive Hypothesis: Assume that S(k) = S R (k) = (k 1) k+1 + holds true for some arbitrary k. Inductive Step: We need to prove that the claim is true for k + 1. In other words, we need to show S(k + 1) = S R (k + 1) = (k) k+ + First, we show S(k + 1) = S R (k + 1). But that is really easy since For the other half, S R (k + 1) = S R (k) + (k + 1) k+1 Definition of S R = S(k) + (k + 1) k+1 Induction Hypothesis = 0 +... + k k + (k + 1) k+1 Definition of S = S(k + 1) Definition of S S R (k + 1) = S R (k) + (k + 1) k+1 Definition of S R (k 1) k+1 + + (k + 1) k+1 Induction Hypothesis = k k+1 + = k k+ + Algebra

CS 110: INDUCTION 3 Conclusion: Since our choice of k in the argument above was arbitrary, we know that our property in (7) holds for all n 0. Recurrences The entire motivation of induction is so that students can prove the complexity of MergeSort. Unfortunately, because of scheduling, there is a one week gap between the induction lecture and the recurrence lecture. Therefore, we would like you to introduce the concept of a recurrence, and then use that with (strong) induction to show how to compute the complexity. That means, you are going to have to motivate recurrence relations. I suggest that you use the following two lecture slides as a guide: Analysis of Merge-Sort public static Comparable[] mergesort(comparable[] A, int low, int high) { if (low < high) { //at least elements? cost = c int mid = (low + high)/; cost = d Comparable[] A1 = mergesort(a, low, mid); cost = T(n/) + e Comparable[] A = mergesort(a, mid+1, high); cost = T(n/) + f return merge(a1,a); cost = gn + h } cost = i... Analysis of Merge-Sort Recurrence: T(n) = c + d + e + f + T(n/) + gn + h T(1) = i First, simplify by dropping lower-order terms Recurrence: T(n) = c + d + e + f + T(n/) + gn + h T(1) = i How do we solve this recurrence? recurrence base case Simplified recurrence: T(n) = T(n/) + cn T(1) = d How do we find the solution? 3 4 Because T (0) = 0, you can actually write the MergeSort recurrence as { c if n = T (n) = T (n/) + cn if n > What want to prove is that T (n) is O(n log n). However, this is not a property of the form P (n). You might want to point out to the students that a property P (n) has to allow you to substitute values into it, like P (k) or P (). But if you plug that in for O(n log n), you get something like O( log ), which makes no sense. Instead, we have to phrase what we want to prove as the following claim: T (n) cn log n This needs to be done by strong induction. Again, be very clear about the steps. First of all, point out that there is no need for a recursive strategy. We are already given a recursive function. When you are given a recursive function, you can usually (but not always) do the inductive proof directly on the recursive function. It was only because we had no recursive function to start with in the earlier examples that we had to figure out what our strategy was before we started. With that observation out of the way, we proceed with the usual steps. Base Step: We prove the claim for n = (we are starting at, there is no need to start earlier). Then c log = c 1 = c, so we are done.

4 DISCUSSION TOPICS Strong Inductive Hypothesis: Assume that, for some arbitrary k, T (m) cm log m holds true for all m k. Inductive Step: We need to prove that the claim is true for k + 1. T (k + 1) = T ((k + 1)/) + c(k + 1) Definition of T [ c k + 1 log k + 1 ] + c(k + 1) Strong Induction Hypothesis = c(k + 1) log k + 1 + c(k + 1) Algebra = c(k + 1)(log(k + 1) 1) + c(k + 1) Algebra = c(k + 1) log(k + 1) Algebra In doing this proof, try to make very clear why we needed strong induction, and why weak induction will not work. Once this is done, you might want to shake things up a bit to see if they are following. Take the following line in MergeSort: int mid = (low + high)/; Change this line to int mid = low+1; Try to the exercise again to compute the new complexity. See if you can get them to guess the complexity before you go through the proof. If the students are following, and you are having a good time, you can do a few other recurrences as well. In each case, set up the recurrence relation, and then use induction to prove the complexity. Linear Search: T (n) = T (n1) + 1 is the recurrence. Prove T (n) = O(n). Binary Search: T (n) = T (n/) + 1 is the recurrence. Prove T (n) = O(log n). QuickSort Worst-Case: T (n) = T (n 1) + n is the recurrence. Prove T (n) = O(n ). However, if the students are not following, you might want to cut your loses with MergeSort and move on to the next suggestion. Flawed Induction A fun exercise that helps students to build up their understanding of induction is to presented a flawed induction proof that shows something ridiculous. Then have them try to find the error. Here are two good examples: Example 4. Claim: Let S(n) = 1 +... + n. For every n 1 (8) S(n) = (n + 1 ) Base Step: The equation (8) is true for n = 1.

CS 110: INDUCTION 5 Inductive Hypothesis: Assume that (8) is true for k. Inductive Step: We prove (8) is true for k + 1. Using algebra, S(k + 1) = S(k) + (k + 1) = (k + 1 ) = (k + 3n + 9 4 ) Example 5. Claim: 5n = 0 for every n 0. Base Step: 5 0 = 0. = (k + 3 ) + (k + 1) = (k + n + 1 4 ) = [(k + 1) + 1 ] Strong Inductive Hypothesis: Assume that 5 m = 0 for every m k. + k + 1 Inductive Step: We prove the claim is true for k + 1. We write k + 1 = m 0 + m 1 where m 0, m 1 are both less than k + 1. By the strong induction hypothesis, 5m 0 = 0 and 5m 1 = 0. Therefore, 5(k + 1) = 5(m 0 + m 1 ) = 5m 0 + 5m 1 = 0 + 0 = 0 Additional Problems If you have any other induction problems that you really like, feel free to introduce them. However, I suggest that you stick to the following guidelines. Avoid the geometric induction puzzles. Stick to properties of functions, or clearly numeric properties, for now. Remember this is 110, not 800. Always remember to use k in the proof. Do not induct on n (e.g. assume true for n 1 and then prove for n), even though that may have appeared on class slides in the past. This is confusing to a new student.