Proof Techniques and Recursion. Proof Techniques Proof by induction –Step 1: Prove the base case –Step 2: Inductive hypothesis, assume theorem is true.

Slides:



Advertisements
Similar presentations
EECS 311: Chapter 2 Notes Chris Riesbeck EECS Northwestern.
Advertisements

Appendix B Solving Recurrence Equations : With Applications to Analysis of Recursive Algorithms.
Recursion (define tell-story (lambda () (print ‘’Once upon a time there was a mountain. ‘’) (print ‘’On the mountain, there was a temple. ‘’) (print ‘’In.
Recursion. Idea: Some problems can be broken down into smaller versions of the same problem Example: n! 1*2*3*…*(n-1)*n n*factorial of (n-1)
Recursion. Binary search example postponed to end of lecture.
1 CSCD 300 Data Structures Recursion. 2 Proof by Induction Introduction only - topic will be covered in detail in CS 320 Prove: N   i = N ( N + 1.
Recursion. Idea: Some problems can be broken down into smaller versions of the same problem Example: n! 1*2*3*…*(n-1)*n n*factorial of (n-1)
1 Chapter 1: Introduction What you have learnt in Comp1220 or Comp1170? What will be taught in Comp 1200? - more Abstract Data Types -efficient algorithms.
Recursive Algorithms Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Chapter 15 Recursive Algorithms. 2 Recursion Recursion is a programming technique in which a method can call itself to solve a problem A recursive definition.
Recursion. Idea: Some problems can be broken down into smaller versions of the same problem Example: n! 1*2*3*…*(n-1)*n n*factorial of (n-1)
CHAPTER 10 Recursion. 2 Recursive Thinking Recursion is a programming technique in which a method can call itself to solve a problem A recursive definition.
analysis, plug ‘n’ chug, & induction
Recursion.  Identify recursive algorithms  Write simple recursive algorithms  Understand recursive function calling  With reference to the call stack.
CS Discrete Mathematical Structures Mehdi Ghayoumi MSB rm 132 Ofc hr: Thur, 9:30-11:30a.
A Review of Recursion Dr. Jicheng Fu Department of Computer Science University of Central Oklahoma.
1 CS 201 Data Structures & Algorithms Chapter 1 Introduction Text: Read Weiss, §1.1 – 1.3 Izmir University of Economics.
Lecture 8. How to Form Recursive relations 1. Recap Asymptotic analysis helps to highlight the order of growth of functions to compare algorithms Common.
Mathematics Review Exponents Logarithms Series Modular arithmetic Proofs.
Chapter 2 - Mathematical Review Functions
1 CE 221 Data Structures & Algorithms Chapter 1 Introduction Text: Read Weiss, §1.1 – 1.3 Izmir University of Economics.
Advance Data Structure and Algorithm COSC600 Dr. Yanggon Kim Chapter 1.
Chapter 1 Introduction. Goals Why the choice of algorithms is so critical when dealing with large inputs Basic mathematical background Review of Recursion.
Chapter 7 Recursion 1CSCI 3333 Data Structures. 2 Recurrent Sequence A recursively defined sequence – First, certain initial values are specified  c.f.,
Analyzing Complexity of Lists OperationSorted Array Sorted Linked List Unsorted Array Unsorted Linked List Search( L, x ) O(logn) O( n ) O( n ) Insert(
Suppose you have a problem involving N data points. Recursive solution of such problem is a follows: If the problem can be solved directly for N points.
1 Joe Meehean.  call themselves directly  or indirectly void f(){... f();... } void g(){... h();... } void h(){... g();... }
Methods of Proofs PREDICATE LOGIC The “Quantifiers” and are known as predicate quantifiers. " means for all and means there exists. Example 1: If we.
Reading – Chapter 10. Recursion The process of solving a problem by reducing it to smaller versions of itself Example: Sierpinski’s TriangleSierpinski’s.
1 COMP3040 Tutorial 1 Analysis of algorithms. 2 Outline Motivation Analysis of algorithms Examples Practice questions.
Design of Algorithms by Induction Part 1 Algorithm Design and Analysis Week 3 Bibliography: [Manber]- Chap.
Recursion. What is recursion? Rules of recursion Mathematical induction The Fibonacci sequence Summary Outline.
 O(1) – constant time  The time is independent of n  O(log n) – logarithmic time  Usually the log is to the base 2  O(n) – linear time  O(n*logn)
Mathematical Background and Linked Lists. 2 Iterative Algorithm for Sum Find the sum of the first n integers stored in an array v : sum (v[], n) temp_sum.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Recursive Solutions Recursion is an extremely powerful problem-solving.
CSC 221: Recursion. Recursion: Definition Function that solves a problem by relying on itself to compute the correct solution for a smaller version of.
Logical Reasoning:Proof Prove the theorem using the basic axioms of algebra.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 3.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 2 Prepared by İnanç TAHRALI.
October 3, 2001CSE 373, Autumn Mathematical Background Exponents X A X B = X A+B X A / X B = X A-B (X A ) B = X AB X N +X N = 2X N 2 N +2 N = 2 N+1.
Foundations II: Data Structures and Algorithms
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Math Review 1.
23 February Recursion and Logarithms CSE 2011 Winter 2011.
1 Review for Quiz 1. 2 Summations 3 Binomial expansion.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
1 Chapter 2 Algorithm Analysis Reading: Chapter 2.
Analysis of Algorithms Spring 2016CS202 - Fundamentals of Computer Science II1.
Chapter 15 Running Time Analysis. Topics Orders of Magnitude and Big-Oh Notation Running Time Analysis of Algorithms –Counting Statements –Evaluating.
Program Development and Design Using C++, Third Edition
Section Recursion 2  Recursion – defining an object (or function, algorithm, etc.) in terms of itself.  Recursion can be used to define sequences.
Section Recursion  Recursion – defining an object (or function, algorithm, etc.) in terms of itself.  Recursion can be used to define sequences.
1 Proofs by Counterexample & Contradiction There are several ways to prove a theorem:  Counterexample: By providing an example of in which the theorem.
Recursion.
CS212: Data Structures and Algorithms
Algorithm Analysis 1.
Recursion Ali.
11.7 – Proof by Mathematical Induction
Recursion Salim Arfaoui.
Analysis of Algorithms CS 477/677
Analysis of Algorithms
Lecture 11. Master Theorem for analyzing Recursive relations
Data Structures Review Session
Analysis of Algorithms
Applied Discrete Mathematics Week 9: Integer Properties
Recursion.
Design of Algorithms by Induction Part 1
Recursion.
Recursive Thinking.
Analysis of Algorithms
Data Structures & Programming
Presentation transcript:

Proof Techniques and Recursion

Proof Techniques Proof by induction –Step 1: Prove the base case –Step 2: Inductive hypothesis, assume theorem is true for all cases up to limit k –Step 3: Show theorem is true for next case (k+1) Proof by counterexample –Prove a statement false by providing a case where it is not correct Proof by contradiction –Assume theorem is false and show that the assumption implies a known property is false

Recursion “A function that is defined in terms of itself is called recursive.” Example: n! 1*2*3*…*(n-1)*n n*factorial of (n-1)

Rules of Recursion 1.Base cases. You must always have some bases cases, which can be solved without recursion. 2.Making progress. For the cases that are to be solved recursively, the recursive call must always be to a case that makes progress toward a base case. 3.Design rule. Assume that all the recursive calls work. 4.Compound interest rule. Never duplicate work by solving the same instance of a problem in separate recursive calls.

Function: factorial int factorial(int n) { if(n == 1) return 1; else return (n*factorial(n-1)); }

Iterative Factorial int factorial(int n) { int i; int product = 1; for(i = n; i > 1; i--) { product = product * i; } return product; }

Linear Recursion At most 1 recursive call at each iteration –Example: Factorial General algorithm –Test for base cases –Recurse Make 1 recursive call Should make progress toward the base case Tail recursion –Recursive call is last operation –Can be easily converted (should be!) to iterative

Higher-Order Recursion Algorithm makes more than one recursive call Binary recursion –Halve the problem and make two recursive calls –Example? Multiple recursion –Algorithm makes many recursive calls –Example?

Example Design a recursive program to produce the following output:

Analyzing Recursive Functions Factorial –Similar to analyzing a loop Previous example Version 3 of Maximum Subsequence Sum problem (pg. 53)

Algorithm find max sum of first half find max sum of second half starting from middle, iterate through list toward beginning and stop when max found return max of first half, second half, and sum of overlap

Recurrence T(1) = 1 T(N) = 2T(N/2) + O(N) T(1) = 1, T(2) = 4 = 2*2, T(4) = 12 = 4*3, T(8) = 32 = 8*4, T(16) = 80 = 16*5 T(N) = N*(k+1) -- if N=2 k T(N) = 2 k *(k+1) T(N) = k2 k + 2 k T(N) = logN(N) + N = NlogN + N = O(NlogN)