Question: Mathematical Analysis of Recursive Algorithms ALGORITHM S ( n ) / / Input: A positive integer n / / Output: The sum of the first
Mathematical Analysis of Recursive Algorithms
ALGORITHM Sn
Input: A positive integer n
Output: The sum of the first n cubes
if n return
else return Sn n n n
a Set up and solve a recurrence relation for the number of times the algo
rithms basic operation is executed.
b How does this algorithm compare with the straightforward nonrecursive
algorithm for computing this sum?
Consider the following recursive algorithm.
ALGORITHM Qn
Input: A positive integer n
if n return
else return Qn n
a Set up a recurrence relation for this functions values and solve it to deter
mine what this algorithm computes.
b Set up a recurrence relation for the number of multiplications made by this
algorithm and solve it
c Set up a recurrence relation for the number of additionssubtractions made
by this algorithm and solve it
Tower of Hanoi
a In the original version of the Tower of Hanoi puzzle, as it was published in
the s by Edouard Lucas, a French mathematician, the world will end
after disks have been moved from a mystical Tower of Brahma. Estimate
the number of years it will take if monks could move one disk per minute.
Assume that monks do not eat, sleep, or die.
b How many moves are made by the ith largest disk i n in this
algorithm?
c Find a nonrecursive algorithm for the Tower of Hanoi puzzle and imple
ment it in the language of your choice.
Restricted Tower of Hanoi Consider the version of the Tower of Hanoi
puzzle in which n disks have to be moved from peg A to peg C using peg
B so that any move should either place a disk on peg B or move a disk from
that peg. Of course, the prohibition of placing a larger disk on top of a smaller
one remains in place, too. Design a recursive algorithm for this problem and
find the number of moves made by it
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
