Professional Documents
Culture Documents
Data Structures: Dr. Abubaker M. F. Abushofa Department of Electrical & Electronic Engineering, Faculty of Engineering
Data Structures: Dr. Abubaker M. F. Abushofa Department of Electrical & Electronic Engineering, Faculty of Engineering
ly
Data Structures
Data Structures EE432
Fall 2018 - 2019
What is Recursion?
What is a Recursion?
• Recursive call: A method call in which the
method being called is the same as the one
Recursion
• You must be careful when using recursion.
• Recursive solutions can be less efficient than
Some Definitions
• Base case: The case for which the solution can
be stated non‐recursively
// base case
Computing Factorial
• Recursive definition
What is 3 factorial?
Computing Factorial
Recursive Computation
Factorial Program
Factorial(0) = 1
Factorial Program
• The function call Factorial(4) should have
value 24, because that is 4 * 3 * 2 * 1 .
Factorial Program
• Now for the general case . . .
• The value of Factorial(n) can be written as n *
Recursive Factorial
int Factorial ( int number )
{
power(5,0) = 1
EE432 Dr. Abubaker Abushofa 19/25
http://www.abushofa.net.ly
Fibonacci Sequence
• Problem: Calculate Nth item in Fibonacci
sequence
Fibonacci Program
int Fibonacci(int n)
{
RevPrint(listData)
Printing in Reverse
void RevPrint ( NodeType* listPtr )
{
Any question?
Department of Electrical and Electronic Engineering
Data Structures EE432
Fall 2018 - 2019