/
n 1 n n factorial of n 1 base case 5 5 4 4 4 3 n 1 n n factorial of n 1 base case 5 5 4 4 4 3

n 1 n n factorial of n 1 base case 5 5 4 4 4 3 - PDF document

tatyana-admore
tatyana-admore . @tatyana-admore
Follow
364 views
Uploaded On 2017-11-23

n 1 n n factorial of n 1 base case 5 5 4 4 4 3 - PPT Presentation

Te Algorithm makes more than one recursivecall ID: 608113

Te Algorithm makes more than one

Share:

Link:

Embed:

Download Presentation from below link

Download Pdf The PPT/PDF document "n 1 n n factorial of n 1 base case 5 5 4..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

É*(n-1)*n¥n*factorial of (n-1)Base Case¥5! = 5*4!¥4! = 4*3!¥3! = 3*2!¥2! = 1*1!¥1! = 1Base case Ð you always need a terminating condition to endFunction: factorialint factorial(int n) {if(n == 1)return 1;elsereturn (n*factorial(n-1)) Te Algorithm makes more than one recursivecall¥Binary recursionÐHalve the problem and make two recursivecallsÐExample?¥Multi Exercises1.Implement and test a method that usestail recursion to convert an array ofintegers into their absolute values.Towers of Hanoi¥Three pegs and a set of disks¥Goal: move all disks from peg 1 to peg 3¥Rules:Ðmo