Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 11

Mathematical Induction and

Recursion
Mathematical Induction

 In general, mathematical induction can be used to prove statements that assert that P(n) is
true for all positive integers n, where P(n) is a propositional function.
 A proof by mathematical induction has two parts, a basis step, where we show that P(1) is
true, and an inductive step, where we show that for all positive integers k, if P(k) is true,
then P(k + 1) is true
Project 1

Provide an example of the application of mathematical induction


Create a video or an animation of your example and discussion
Recursion
Recursion
 Sometimes a problem is too difficult or too complex to solve because it is too big. If the
problem can be broken down into smaller versions of itself, we may be able to find a way
to solve one of these smaller versions and then be able to build up to a solution to the
entire problem.
 Recursion is the process of defining a problem (or the solution to a problem) in terms of (a
simpler version of) itself.
 Recursive algorithms break down a problem into smaller pieces which you either already
know the answer to, or can solve by applying the same algorithm to each piece, and then
combining the results.
 In computer science, recursion is a programming technique using function or algorithm
that calls itself one or more times until a specified condition is met at which time the rest
of each repetition is processed from the last one called to the first.
Factorial
 The factorial function, often denoted as n!, describes the operation of multiplying a number by
all the positive integers smaller than it.
 For example, 5! = 5*4*3*2*1. And 9! = 9*8*7*6*5*4*3*2*1.
 Take a good close look at the above, and you may notice something interesting. 5! can be written
much more concisely as 5! = 5*4!.

 And 4! is actually 4*3!.

 the factorial function is recursive, it is defined in terms of itself.


Recursive vs Iterative Algorithms

 The Recursion and Iteration both repeatedly execute the set of instructions.
 Recursion is when a statement in a function calls itself repeatedly.
 The iteration is when a loop repeatedly executes until the controlling
condition becomes false.
Recursive vs Iterative Algorithms
Recursive vs Iterative Algorithms
Recursive vs Iterative Algorithms
Programming Projects
Write programs with these input and
output
1. Given a nonnegative integer n, find the nth Fibonacci number using iteration and recursion
2. Given a list of integers and an element x, locate x in this list using a recursive
implementation of a binary search.

You might also like