0% found this document useful (0 votes)
3 views41 pages

CH 3

Chapter 3 discusses recursive functions, defining recursion as a technique where a function calls itself to simplify complex problems. It covers common recurrence relations and methods for solving them, including the Master Method, Recursion Tree Method, Iteration Method, and Substitution Method. The chapter emphasizes the importance of base cases in recursion to prevent infinite loops.

Uploaded by

mtech3707
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views41 pages

CH 3

Chapter 3 discusses recursive functions, defining recursion as a technique where a function calls itself to simplify complex problems. It covers common recurrence relations and methods for solving them, including the Master Method, Recursion Tree Method, Iteration Method, and Substitution Method. The chapter emphasizes the importance of base cases in recursion to prevent infinite loops.

Uploaded by

mtech3707
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 41

MATHEMATICAL ANALYSIS OF RECURSIVE

FUNCTION

Chapter3

Prepared by: Enas Abu Samra


KEY POINTS OF CHAPTER3

• Recursive function definition.


• Idea of recursive function.
• Examples of recursive functions.
• Common recurrence relations.
• Methods for solving recurrences:
✓ Master Method
✓ Recursion Tree Method
✓ Iteration Method
✓ Substitution Method
What is the Recursive Function?
RECURSIVE FUNCTION DEFINITION

• Recursion is the technique of making a function call itself. This technique


provides a way to break complicated problems down into simple problems which are
easier to solve.

• Algorithmically: a way to design solutions to problems by divide-and-conquer.


• Semantically: a programming technique where a function calls itself.
DIVIDE AND CONQUER TECHNIQUE

• Divide and conquer is an algorithm design paradigm based on multi-branched


recursion. It works by recursively breaking down (reducing) a problem into (two or
more) sub-problems of the same (or related type), until these become simple
enough to be solved directly. The solutions to the sub-problems are then combined
to give a solution to the original problem.
IDEA OF RECURSIVE FUNCTION

• We can distill the idea of recursion into two simple rules:


➢ Each recursive call should be on a smaller instance of the same problem, that is, a smaller
subproblem.
➢ The recursive calls must eventually reach a base case, which is solved without further
recursion.
Note:
If you forget to include a base case, or your recursive cases fail to eventually reach a
base case, then infinite recursion happens. Infinite recursion is a special case of an
infinite loop when a recursive function fails to stop recursing.
EXAMPLE (1) OF RECURSIVE FUNCTION
TRACING OF RECURSIVE FUNCTION

• The execution of a recursive function is usually illustrated using a recursion


trace.
• Each new recursive function call is indicated by a downward arrow to a new
invocation.
• When the function returns, an arrow showing this return is drawn and the return
value may be indicated alongside this arrow.
RECURSION TRACE FOR EXAMPLE( 1)
COMPLEXITY OF EXAMPLE(1)
EXAMPLE (2) OF RECURSIVE FUNCTION
What is the Recurrence Relations?
COMMON RECURRENCE RELATIONS

• A recurrence relation is an equation that defines a sequence based on a rule that gives
the next term as a function of the previous term(s).
COMMON RECURRENCE RELATIONS
METHODS FOR SOLVING RECURRENCES

✓ Master Method
✓ Recursion Tree Method
✓ Iteration Method
✓ Substitution Method
The Master Method
MASTER METHOD
MASTER EXAMPLES
MASTER EXAMPLES
MASTER EXAMPLES
The Recursion Tree Method
RECURSION TREE METHOD
STEPS OF RECURSION TREE METHOD
RECURSION TREE EXAMPLES
RECURSION TREE EXAMPLES
RECURSION TREE EXAMPLES
RECURSION TREE EXAMPLES
The Iteration Method
ITERATION METHOD

Solution Steps:
1. Iteration Step
2. Find (i) and pattern
ITERATION EXAMPLES
ITERATION EXAMPLES
ITERATION EXAMPLES
ITERATION EXAMPLES
The Substitution Method
SUBSTITUTION METHOD
SUBSTITUTION EXAMPLES
SUBSTITUTION EXAMPLES
SUBSTITUTION EXAMPLES
SUBSTITUTION EXAMPLES
EXTRA EXAMPLE

➢ Solve the following example using master, recursion tree and iteration methods:
𝒏
T(n) = T( ) + n
𝟑

T(1) = 1
END OF CHAPTER3

You might also like