Unit III
Unit III
UNIT III
ALGORITHMIC PROBLEM
SOLVING AND ANALYSIS
What is an Algorithm
• In his absence, the wolf would eat the goat, and the goat
would eat the cabbage.
How fast the algorithm can run, if we double the input size
Units for Measuring Running Time
Orders of Growth
Orders of Growth
ALGORITHM F(n)
//Computes n! recursively
//Input: A nonnegative integer n
//Output: The value of n!
if n = 0 return 1
else return F(n − 1) ∗ n
Mathematical Analysis of Recursive Algorithms
if n = 0, return 1
Mathematical Analysis of Recursive Algorithms
Mathematical Analysis of Recursive Algorithms
General Plan for Analyzing the Time Efficiency
of Recursive Algorithms
1. Decide on a parameter (or parameters)
indicating an input’s size.
2. Identify the algorithm’s basic operation
3. Check whether the number of times the basic
operation is executed can vary on different
inputs of the same size; if it can, the worst-case,
average-case, and best-case efficiencies must be
investigated separately.
4. Set up a recurrence relation, with an appropriate
initial condition, for the number of times the
basic operation is executed.
5. Solve the recurrence or, at least, ascertain the
order of growth of its solution.