0% found this document useful (0 votes)
4 views2 pages

Recursion Notes - A2 CS

Recursion is a process where a function calls itself, defined by a base case and a general case. It can simplify complex problems and reduce the number of programming statements, but may lead to stack overflow if calls are too repetitive. Key features include having a base case, a general case, and utilizing a stack for managing recursive calls.

Uploaded by

Huzaifa Siddiq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Recursion Notes - A2 CS

Recursion is a process where a function calls itself, defined by a base case and a general case. It can simplify complex problems and reduce the number of programming statements, but may lead to stack overflow if calls are too repetitive. Key features include having a base case, a general case, and utilizing a stack for managing recursive calls.

Uploaded by

Huzaifa Siddiq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Recursion Notes

What is Recursion?
●​ Recursion is a process using a function or procedure that is defined in terms of itself and
calls itself.
●​ The process is defined using a base case, a terminating solution to a process that is not
recursive,
●​ And a general case, a solution to a process that is recursively defined.

What are the benefits of Recursion?


●​ Recursive solutions can contain fewer programming statements than an iterative solution.
●​ The solutions can solve complex problems in a simpler way than an iterative solution.

Why are recursive solutions more beneficial than iterative solutions?


●​ Recursive solutions can contain fewer programming statements than an iterative solution.
●​ The solutions can solve complex problems in a simpler way than an iterative solution.

Name the problem that can occur when using recursion.


●​ stack overflow

Why may stack overflow occur?


●​ if recursive calls to procedures and functions are very repetitive, there is a very heavy use
of the stack, which can lead to stack overflow

State a disadvantage of using recursion


●​ When using recursive solutions, if recursive calls to procedures and functions are very
repetitive, there is a very heavy use of the stack, which can lead to stack overflow.

What is winding?
●​ process which occurs when a recursive function or procedure is called until the base case
is found.

What is unwinding?
●​ process which occurs when a recursive function finds the base case and the function
returns the values.

What is meant by a base case?


●​ a terminating solution to a process that is not recursive.

What is meant by a general case?


●​ a solution to a process that is recursively defined.

Explain how a compiler makes use of a stack when translating recursive programming code.
●​ The compiler must produce object code to
●​ …push return addresses / values of local variables onto a stack
●​ …with each recursive call // … to set up winding
●​ …pop return addresses / values of local variables off the stack …
●​ …after the base case is reached // … to implement unwinding.

State three essential features of recursion.


●​ Must have a base case/stopping condition
●​ Must have a general case
●​ … which calls itself (recursively) // Defined in terms of itself
●​ … which changes its state and moves towards the base case
●​ Unwinding can occur once the base case is reached.

Explain the reasons why a stack is a suitable Abstract Data Type (ADT) to implement recursion.
●​ A stack is a LIFO data structure
●​ Each recursive call is pushed onto the stack
●​ …. and is then popped as the function ends
●​ Enables backtracking/unwinding
●​ … to maintain the required order.

You might also like