Recursion and Iteration (OCR A-Level Computer Science): Flashcards

📚Flashcards
Recursion and Iteration
Sign up to keep revising.Create a free account to study more flashcards and track your progress.

Practise the cards

13 cards from this deck

Show

What is recursion?

Function calls itself to solve smaller instances of same problem

Base case in recursion

Condition that stops the recursion

Recursive case

Part of function that calls itself with smaller/simpler input

Call stack role in recursion

Stores current state of each call; unwinds when base case reached

What is iteration?

Uses loops (FOR/WHILE) to repeat code until condition is met

Which uses more memory: recursion or iteration?

Recursion uses more memory due to call stack

Which is faster: recursion or iteration?

Iteration is generally faster & more efficient

Stack overflow risk

Can occur in recursion if base case is missing

Infinite loop risk

Can occur in iteration if loop condition is incorrect

Key benefit of recursion

Simplifies code for complex problems; more elegant & clear

Key benefit of iteration

More efficient; uses less memory; avoids stack overflow

Why does recursion use more memory?

Each recursive call uses stack memory; can cause stack overflow

Trace tables purpose

Track variable values at each step to debug & understand behaviour

Explore OCR A-Level Computer Science Revision Notes by Topics

Explore OCR A-Level Computer Science Model Answers by Topics

Explore OCR A-Level Computer Science Quizzes by Topics

Explore OCR A-Level Computer Science Exam Questions by Topics

Join 100,000+ A-Level students studying Flashcards with us.

Select your subjects, and get access to A+ resources today.