GoConqr has a new look! Let us know what you think.

Notes

Unit 2 Notes

Jacob Pienkowski English 1 page

Content of the notes (1)

Page 1

Recursion aims to solve a large problem by solving increasingly smaller instances of the problem.

Unit 2 Notes

The Droste effect is an example of recursion in art.

One of the common examples of recursion used in programming is a factorial. A factorial, written as n! is every number from n to 1 multiplied together.

For a recursive solution, it helps to think of n! as n * (n-1)! instead.

We can now make a solution in pseudocode:

function factorial is: input: integer n such that n >= 1

output: [n × (n-1) × (n-2) × … × 1]

1. if n is >= 1, return [ n × factorial(n-1) ]

2. otherwise, return 1

end factorial

function factorial(ByVal n as integer)

if n >= 1 then

return n * factorial(n-1) 'recursive call

else

return 1

end if

end function

sub main()

console.writeline(factorial(10))

end sub

RECURSION

Information

Description
Covers Recursion, Lists & Pointers, Stacks & Queues and Graphs & Trees
Created by
Jacob Pienkowski · Nov 2014
Updated
May 8, 2016
Views
90
Rating

Feedback

What is it about?

What do you think of the new look?

How do you like it?