0% found this document useful (0 votes)
129 views2 pages

General Plan For Analyzing Efficiency of Recursive Algorithms

Uploaded by

9111roshan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
129 views2 pages

General Plan For Analyzing Efficiency of Recursive Algorithms

Uploaded by

9111roshan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 2

General plan for analyzing efficiency of recursive

algorithms:
1. Decide on parameter n indicating input size

2. Identify algorithm’s basic operation

3. Check whether the number of times the basic operation is executed depends only on the
input size n. If it also depends on the type of input, investigate worst, average, and best
case efficiency separately.

4. Set up recurrence relation, with an appropriate initial condition, for the number of times
the algorithm’s basic operation is executed.

5. Solve the recurrence.

Example: Factorial function

ALGORITHM Factorial (n)

//Computes n! recursively

//Input: A nonnegative integer n

//Output: The value of n!

if n = = 0

return 1
else

return Factorial (n – 1) * n

Analysis:
1. Input size: given number = n

2. Basic operation: multiplication

3. NO best, worst, average cases.

4. Let M (n) denotes number of multiplications.

You might also like