Unit 2 Notes

Description

Covers Recursion, Lists & Pointers, Stacks & Queues and Graphs & Trees
Jacob Pienkowski
Note by Jacob Pienkowski, updated more than 1 year ago
Jacob Pienkowski
Created by Jacob Pienkowski over 10 years ago
55
1
1 2 3 4 5 (0)

Resource summary

Page 1

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

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 >= 1output: [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

Show full summary Hide full summary

0 comments

There are no comments, be the first and leave one below:

Similar

Computing Hardware - CPU and Memory
ollietablet123
French diet and health vocab
caitlindavies8
Geography Coastal Zones Flashcards
Zakiya Tabassum
Cells - Biology AQA B2.1.1
benadyl10
AQA Biology 12.1 cellular organisation
Charlotte Hewson
AQA Biology 8.1 structure of DNA
Charlotte Hewson
Germany 1918-39
Cam Burke
PSYA1 - attachment, AQA psychology
T W
AS Biology Unit 1
lilli.atkin
Biology Unit 1a - GCSE - AQA
RosettaStoneDecoded