Recursion:
Tail recursion, Head Recursion
Session No.: 8
Course Name: Data Strucutres
Course Code: R1UC308B
Instructor Name: Dr. Subhash Chandra Gupta
Duration: 50 mins
Date of Conduction of Class: 8 Sep 2025
Galgotias University 1
Review
Matrices and their properties:
Matrices Addition
Matrices Subtraction
Matrices Multiplication
Galgotias University 2
Pre Class
Assessment [1-mins]
Galgotias University 3
[1-mins]
What is Recursion?
Galgotias University 4
Learning Outcomes [2-mins]
By the end of this session, You will be able to:
Differentiate between head recursion and
tail recursion by analyzing their structure
and execution flow...
Implement recursive functions in C using
both head and tail recursion to solve simple
computational problems.
Galgotias University 5
Session Outline
• Introduction to Recursion
• Types of Recursion: Tail recursion & Head Recursion
• Applications of Recursion
• Provide hands-on activities and reinforce learning
through an interactive WooClap and WooFlash tools.
Galgotias University 6
Activity-1 (Think – Pair – [1-mins]
Share)
What is the need of Recursion: Tail
recursion? recursion, Head
Recursion
Galgotias University 7
Introduction to Recursion
• The process in which a function calls itself directly or indirectly is
called recursion and the corresponding function is called a recursive
function.
• A recursive algorithm takes one step toward solution and then
recursively call itself to further move. The algorithm stops once we
reach the solution.
• Since called function may further call itself, this process might
continue forever. So it is essential to provide a base case to terminate
this recursion process.
GSCALE full form and date 8
Recursion
GSCALE full form and date 9
Recursion
GSCALE full form and date 10
Recursion: Tail recursion
Tail recursion is defined as a recursive function in which the recursive call is the last statement that is
executed by the function. So basically nothing is left to execute after the recursion call .
// An example of tail
recursive function
void print(int n)
{
if (n < 0)
return;
printf("%d ", n);
print(n - 1);
}
GSCALE full form and date 12
GSCALE full form and date 13
void print_ascending(int n) { [5-mins]
// Base case
if (n == 0) {
return;
}
// Recursive call (head recursion)
print_ascending(n - 1);
// Processing after the recursive call In this print_ascending example,
returns
printf("%d ", n); the print_ascending(n - 1) call happens
} before printf("%d ", n).
int main() { This results in the numbers being printed in
print_ascending(5); // Output: 1 2 3 4 5 ascending order because the printf statement for
return 0; a given n is executed only after all calls for n-1, n-
} 2, and so on, have completed and returned.
Galgotias University 14
[5-mins]
Galgotias University 22
Post Class Assessment
Galgotias University 23
Summary [1-mins]
Galgotias University 24
Ensure attainment of LO’s in alignment to the
[2-mins]
learning activities:
Differentiate between head recursion and
tail recursion by analyzing their structure
and execution flow...
Implement recursive functions in C using
both head and tail recursion to solve simple
computational problems.
Galgotias University 25
[1-min]
Next Session:
Nested recursion, Removal of
recursion.
Galgotias University 26
Review and Reflection from students
Go to the LMS and fill out the feedback
form
Galgotias University 27