top of page

Practice Recursion

  • Karla G
  • 28 mar 2015
  • 1 Min. de lectura

Questions:

1.- What is a recursion?

2.- In this code:

function factorial (n is a non-negative integer)

if n is 0 then

return 1 [by the convention that 0! = 1]

else

return factorial(n – 1) times n [recursively invoke factorial with the parameter 1 less than n]

end if

end function

When n=4, how many times the function is re-executed? (Not counting the first time is called, only the recursions)

3.- State the operations that the last program makes, for example, the first line of operation would be:

factorial(4-1) times 4 --> 3!*4

Continue...

Answers:

1.- A function that calls itself as a part of a process dividing the tasks in more little and little tasks.

2.- 4 times.

3.-

factorial(4-1) times 4 --> 3!*4

factorial(3-1) times 3 --> 2!*3

factorial(2-1) times 2 --> 1!*2

factorial(1-1) times 1 --> 0!*1

 
 
 

Commenti


 THE ARTIFACT MANIFAST: 

 

This is a great space to write long text about your company and your services. You can use this space to go into a little more detail about your company. Talk about your team and what services you provide. Tell your visitors the story of how you came up with the idea for your business and what makes you different from your competitors. Make your company stand out and show your visitors who you are. Tip: Add your own image by double clicking the image and clicking Change Image.

 UPCOMING EVENTS: 

 

10/31/23:  Scandinavian Art Show

 

11/6/23:  Video Art Around The World

 

11/29/23:  Lecture: History of Art

 

12/1/23:  Installations 2023 Indie Film Festival

 FOLLOW THE ARTIFACT: 
  • Facebook B&W
  • Twitter B&W
  • Instagram B&W
 RECENT POSTS: 
 SEARCH BY TAGS: 

© 2023 by Karla Lugo. Proudly created with Wix.com

bottom of page