0% found this document useful (0 votes)
716 views26 pages

Stack, Queue and Recursion in Data Structure

The document provides information about stacks, including: - Stacks are last-in, first-out data structures where only the top element can be accessed. Push adds an element and pop removes the top element. - Common stack operations are described like push, pop, peek, isFull, and isEmpty. Algorithms for these operations are presented. - Stacks can be implemented using arrays or linked lists. Several applications of stacks are discussed like expression evaluation, backtracking, function calls, and memory management.

Uploaded by

chitvan Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
716 views26 pages

Stack, Queue and Recursion in Data Structure

The document provides information about stacks, including: - Stacks are last-in, first-out data structures where only the top element can be accessed. Push adds an element and pop removes the top element. - Common stack operations are described like push, pop, peek, isFull, and isEmpty. Algorithms for these operations are presented. - Stacks can be implemented using arrays or linked lists. Several applications of stacks are discussed like expression evaluation, backtracking, function calls, and memory management.

Uploaded by

chitvan Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 26

Data Structure

Unit-4
Stacks, Queues and Recursion
Introduction to stacks:-

A stack is an Abstract Data Type (ADT), commonly used in most programming languages. It is
named stack as it behaves like a real-world stack, for example – a deck of cards or a pile of
plates, etc.

A real-world stack allows operations at one end only. For example, we can place or remove a
card or plate from the top of the stack only. Likewise, Stack ADT allows all data operations at
one end only. At any given time, we can only access the top element of a stack.
This feature makes it LIFO data structure. LIFO stands for Last-in-first-out. Here, the element
which is placed (inserted or added) last, is accessed first. In stack terminology, insertion
operation is called PUSH operation and removal operation is called POP operation.
Stack is an abstract data type with a bounded(predefined) capacity. It is a simple data structure
that allows adding and removing elements in a particular order. Every time an element is added,
it goes on the top of the stack and the only element that can be removed is the element that is at
the top of the stack, just like a pile of objects.

Basic features of Stack


1. Stack is an ordered list of similar data type.
2. Stack is a LIFO(Last in First out) structure or we can say FILO(First in Last out).
3. push() function is used to insert new elements into the Stack and pop() function is used to
remove an element from the stack. Both insertion and removal are allowed at only one
end of Stack called Top.
4. Stack is said to be in Overflow state when it is completely full and is said to be
in Underflow state if it is completely empty.
Stack Representation
The following diagram depicts a stack and its operations −

A stack can be implemented by means of Array, Structure, Pointer, and Linked List. Stack can
either be a fixed size one or it may have a sense of dynamic resizing. Here, we are going to
implement stack using arrays, which makes it a fixed size stack implementation.

Basic Operations
Stack operations may involve initializing the stack, using it and then de-initializing it. Apart
from these basic stuffs, a stack is used for the following two primary operations −
 push() − Pushing (storing) an element on the stack.
 pop() − Removing (accessing) an element from the stack.
When data is PUSHed onto stack.
To use a stack efficiently, we need to check the status of stack as well. For the same purpose,
the following functionality is added to stacks −
 peek() − get the top data element of the stack, without removing it.
 isFull() − check if stack is full.
 isEmpty() − check if stack is empty.
At all times, we maintain a pointer to the last PUSHed data on the stack. As this pointer always
represents the top of the stack, hence named top. The top pointer provides top value of the stack
without actually removing it.

Push Operation
The process of putting a new data element onto stack is known as a Push Operation. Push
operation involves a series of steps −
 Step 1 − Checks if the stack is full.
 Step 2 − If the stack is full, produces an error and exit.
 Step 3 − If the stack is not full, increments top to point next empty space.
 Step 4 − Adds data element to the stack location, where top is pointing.
 Step 5 − Returns success.

If the linked list is used to implement the stack, then in step 3, we need to allocate space
dynamically.

Algorithm for PUSH Operation

A simple algorithm for Push operation can be derived as follows −


begin procedure push: stack, data

if stack is full
return null
endif

top ← top + 1
stack[top] ← data

end procedure

Implementation of this algorithm in C, is very easy. See the following code −


Example
void push(int data) {
if(!isFull()) {
top = top + 1;
stack[top] = data;
} else {
printf("Could not insert data, Stack is full.\n");
}
}

Pop Operation
Accessing the content while removing it from the stack, is known as a Pop Operation. In an
array implementation of pop() operation, the data element is not actually removed,
instead top is decremented to a lower position in the stack to point to the next value. But in
linked-list implementation, pop() actually removes data element and deallocates memory space.
A Pop operation may involve the following steps −
 Step 1 − Checks if the stack is empty.
 Step 2 − If the stack is empty, produces an error and exit.
 Step 3 − If the stack is not empty, accesses the data element at which top is pointing.
 Step 4 − Decreases the value of top by 1.
 Step 5 − Returns success.

Algorithm for Pop Operation

A simple algorithm for Pop operation can be derived as follows −


begin procedure pop: stack

if stack is empty
return null
endif

data ← stack[top]
top ← top - 1
return data

end procedure

Implementation of this algorithm in C, is as follows −


Example
int pop(int data) {

if(!isempty()) {
data = stack[top];
top = top - 1;
return data;
} else {
printf("Could not retrieve data, Stack is empty.\n");
}
}
peek()
Algorithm of peek() function −
begin procedure peek
return stack[top]
end procedure
Implementation of peek() function in C programming language −
Example
int peek() {
return stack[top];
}

isfull()
Algorithm of isfull() function −
begin procedure isfull

if top equals to MAXSIZE


return true
else
return false
endif

end procedure
Implementation of isfull() function in C programming language −
Example
bool isfull() {
if(top == MAXSIZE)
return true;
else
return false;
}

isempty()
Algorithm of isempty() function −
begin procedure isempty

if top less than 1


return true
else
return false
endif

end procedure
Implementation of isempty() function in C programming language is slightly different. We
initialize top at -1, as the index in array starts from 0. So we check if the top is below zero or -1
to determine if the stack is empty. Here's the code −
Example
bool isempty() {
if(top == -1)
return true;
else
return false;
}

Implementation of stacks
You can perform the implementation of stacks in data structures using two data structures that
are an array and a linked list.

 Array: In array implementation, the stack is formed using an array. All the operations are
performed using arrays. You will see how all operations can be implemented on the stack in
data structures using an array data structure.

 Linked-List: Every new element is inserted as a top element in the linked list implementation
of stacks in data structures. That means every newly inserted element is pointed to the top.
Whenever you want to remove an element from the stack, remove the node indicated by the
top, by moving the top to its previous node in the list.
Application of Stack in Data Structures:-
Here are the top 7 applications of the stack in data structure:
 Expression Evaluation and Conversion
 Backtracking
 Function Call
 Parentheses Checking
 String Reversal
 Syntax Parsing
 Memory Management
Now you will understand all the applications one at a time.

1. Expression Evaluation and Conversion


The way to write arithmetic expression is known as a notation. An arithmetic expression can be
written in three different but equivalent notations, i.e., without changing the essence or output
of an expression. These notations are −

 Infix Notation
 Prefix (Polish) Notation
 Postfix (Reverse-Polish) Notation
These notations are named as how they use operator in expression. We shall learn the same here
in this chapter.
Infix Notation
We write expression in infix notation, e.g. a - b + c, where operators are used in-between
operands. It is easy for us humans to read, write, and speak in infix notation but the same does
not go well with computing devices. An algorithm to process infix notation could be difficult
and costly in terms of time and space consumption.
Prefix Notation
In this notation, operator is prefixed to operands, i.e. operator is written ahead of operands. For
example, +ab. This is equivalent to its infix notation a + b. Prefix notation is also known
as Polish Notation.
Postfix Notation
This notation style is known as Reversed Polish Notation. In this notation style, the operator
is postfixed to the operands i.e., the operator is written after the operands. For example, ab+.
This is equivalent to its infix notation a + b.
The following table briefly tries to show the difference in all three notations −

Sr.No. Infix Notation Prefix Notation Postfix Notation

1 a+b +ab ab+

2 (a + b) ∗ c ∗+abc ab+c∗

3 a ∗ (b + c) ∗a+bc abc+∗

4 a/b+c/d +/ab/cd ab/cd/+

5 (a + b) ∗ (c + d) ∗+ab+cd ab+cd+∗

6 ((a + b) ∗ c) - d -∗+abcd ab+c∗d-

2. Backtracking

Backtracking is a recursive algorithm mechanism that is used to solve optimization problems.


To solve the optimization problem with backtracking, you have multiple solutions; it does not
matter if it is correct. While finding all the possible solutions in backtracking, you store the
previously calculated problems in the stack and use that solution to resolve the following issues.
The N-queen problem is an example of backtracking, a recursive algorithm where the stack is
used to solve this problem.

3. Function Call

Whenever you call one function from another function in programming, the reference of calling
function stores in the stack. When the function call is terminated, the program control moves
back to the function call with the help of references stored in the stack.
So stack plays an important role when you call a function from another function.
4. Parentheses Checking

Stack in data structures is used to check if the parentheses like ( ), { } are valid or not in
programing while matching opening and closing brackets are balanced or not.
So it stores all these parentheses in the stack and controls the flow of the program.
For e.g ((a + b) * (c + d)) is valid but {{a+b})) *(b+d}] is not valid.
5. String Reversal

Another exciting application of stack is string reversal. Each character of a string gets stored in
the stack.
The string's first character is held at the bottom of the stack, and the last character of the string is
held at the top of the stack, resulting in a reversed string after performing the pop operation.

6. Syntax Parsing

Since many programming languages are context-free languages, the stack is used for syntax
parsing by many compilers.

7. Memory Management

Memory management is an essential feature of the operating system, so the stack is heavily used
to manage memory.
With that, you have reached the end of this article on Stacks in Data Structures.

Introduction to queues:-
Queue is an abstract data structure, somewhat similar to Stacks. Unlike stacks, a queue is open at both its
ends. One end is always used to insert data (enqueue) and the other is used to remove data (dequeue).
Queue follows First-In-First-Out methodology, i.e., the data item stored first will be accessed first.
A real-world example of queue can be a single-lane one-way road, where the vehicle enters first, exits
first. More real-world examples can be seen as queues at the ticket windows and bus-stops.
Basic features of Queue
1. Like stack, queue is also an ordered list of elements of similar data types.
2. Queue is a FIFO( First in First Out ) structure.
3. Once a new element is inserted into the Queue, all the elements inserted before the new
element in the queue must be removed, to remove the new element.
4. peek( ) function is oftenly used to return the value of first element without dequeuing it.

Queue Representation
As we now understand that in queue, we access both ends for different reasons. The following diagram
given below tries to explain queue representation as data structure −

As in stacks, a queue can also be implemented using Arrays, Linked-lists, Pointers and Structures. For
the sake of simplicity, we shall implement queues using one-dimensional array.

Basic Operations
Queue operations may involve initializing or defining the queue, utilizing it, and then completely erasing
it from the memory. Here we shall try to understand the basic operations associated with queues −
 enqueue() − add (store) an item to the queue.
 dequeue() − remove (access) an item from the queue.
Few more functions are required to make the above-mentioned queue operation efficient. These are −
 peek() − Gets the element at the front of the queue without removing it.
 isfull() − Checks if the queue is full.
 isempty() − Checks if the queue is empty.
In queue, we always dequeue (or access) data, pointed by front pointer and while enqueing (or storing)
data in the queue we take help of rear pointer.
Let's first learn about supportive functions of a queue −
peek()
This function helps to see the data at the front of the queue. The algorithm of peek() function is as
follows −
Algorithm
begin procedure peek
return queue[front]
end procedure
Implementation of peek() function in C programming language −
Example
int peek() {
return queue[front];
}

isfull()
As we are using single dimension array to implement queue, we just check for the rear pointer to reach at
MAXSIZE to determine that the queue is full. In case we maintain the queue in a circular linked-list, the
algorithm will differ. Algorithm of isfull() function −
Algorithm
begin procedure isfull

if rear equals to MAXSIZE


return true
else
return false
endif

end procedure
Implementation of isfull() function in C programming language −
Example
bool isfull() {
if(rear == MAXSIZE - 1)
return true;
else
return false;
}

isempty()
Algorithm of isempty() function −
Algorithm
begin procedure isempty

if front is less than MIN OR front is greater than rear


return true
else
return false
endif

end procedure
If the value of front is less than MIN or 0, it tells that the queue is not yet initialized, hence empty.
Here's the C programming code −
Example
bool isempty() {
if(front < 0 || front > rear)
return true;
else
return false;
}

Enqueue Operation
Queues maintain two data pointers, front and rear. Therefore, its operations are comparatively difficult
to implement than that of stacks.
The following steps should be taken to enqueue (insert) data into a queue −
 Step 1 − Check if the queue is full.
 Step 2 − If the queue is full, produce overflow error and exit.
 Step 3 − If the queue is not full, increment rear pointer to point the next empty space.
 Step 4 − Add data element to the queue location, where the rear is pointing.
 Step 5 − return success.

Sometimes, we also check to see if a queue is initialized or not, to handle any unforeseen situations.

Algorithm for enqueue operation


procedure enqueue(data)

if queue is full
return overflow
endif

rear ← rear + 1
queue[rear] ← data
return true

end procedure
Implementation of enqueue() in C programming language −
Example
int enqueue(int data)
if(isfull())
return 0;

rear = rear + 1;
queue[rear] = data;

return 1;
end procedure

Dequeue Operation
Accessing data from the queue is a process of two tasks − access the data where front is pointing and
remove the data after access. The following steps are taken to perform dequeue operation −
 Step 1 − Check if the queue is empty.
 Step 2 − If the queue is empty, produce underflow error and exit.
 Step 3 − If the queue is not empty, access the data where front is pointing.
 Step 4 − Increment front pointer to point to the next available data element.
 Step 5 − Return success.

Algorithm for dequeue operation


procedure dequeue

if queue is empty
return underflow
end if

data = queue[front]
front ← front + 1
return true

end procedure
Implementation of dequeue() in C programming language −
Example
int dequeue() {
if(isempty())
return 0;

int data = queue[front];


front = front + 1;

return data;
}

Implementation of Queue:-
Queue can be implemented using an Array, Stack or Linked List. The easiest way of
implementing a queue is by using an Array.

Initially the head(FRONT) and the tail(REAR) of the queue points at the first index of the array
(starting the index of array from 0). As we add elements to the queue, the tail keeps on moving
ahead, always pointing to the position where the next element will be inserted, while
the head remains at the first index.
When we remove an element from Queue, we can follow two possible approaches (mentioned
[A] and [B] in above diagram). In [A] approach, we remove the element at head position, and
then one by one shift all the other elements in forward position.

In approach [B] we remove the element from head position and then move head to the next
position.

In approach [A] there is an overhead of shifting the elements one position forward every time
we remove the first element.

In approach [B] there is no such overhead, but whenever we move head one position ahead, after
removal of first element, the size on Queue is reduced by one space each time.

Applications of Queue:-
Queue, as the name suggests is used whenever we need to manage any group of objects in an
order in which the first one coming in, also gets out first while the others wait for their turn, like
in the following scenarios:

1. Serving requests on a single shared resource, like a printer, CPU task scheduling etc.

2. In real life scenario, Call Center phone systems uses Queues to hold people calling them
in an order, until a service representative is free.

3. Handling of interrupts in real-time systems. The interrupts are handled in the same order
as they arrive i.e First come first served.

Circular Queues:-
Circular Queue is also a linear data structure, which follows the principle of FIFO(First In First
Out), but instead of ending the queue at the last position, it again starts from the first position
after the last, hence making the queue behave like a circular data structure.

Basic features of Circular Queue


1. In case of a circular queue, head pointer will always point to the front of the queue,
and tail pointer will always point to the end of the queue.
2. Initially, the head and the tail pointers will be pointing to the same location, this would
mean that the queue is empty.
3. New data is always added to the location pointed by the tail pointer, and once the data is
added, tail pointer is incremented to point to the next available location.

4. In a circular queue, data is not actually removed from the queue. Only the head pointer is
incremented by one position when dequeue is executed. As the queue data is only the
data between head and tail, hence the data left outside is not a part of the queue anymore,
hence removed.

5. The head and the tail pointer will get reinitialised to 0 every time they reach the end of
the queue.
6. Also, the head and the tail pointers can cross each other. In other words, head pointer can
be greater than the tail. Sounds odd? This will happen when we dequeue the queue a
couple of times and the tail pointer gets reinitialised upon reaching the end of the queue.

Going Round and Round

Another very important point is keeping the value of the tail and the head pointer within the
maximum queue size.

In the diagrams above the queue has a size of 8, hence, the value of tail and head pointers will
always be between 0 and 7.

This can be controlled either by checking everytime whether tail or head have reached
the maxSize and then setting the value 0 or, we have a better way, which is, for a value x if we
divide it by 8, the remainder will never be greater than 8, it will always be between 0 and 0,
which is exactly what we want.

So the formula to increment the head and tail pointers to make them go round and round over
and again will be, head = (head+1) % maxSize or tail = (tail+1) % maxSize

Application of Circular Queue

Below we have some common real-world examples where circular queues are used:

1. Computer controlled Traffic Signal System uses circular queue.

2. CPU scheduling and Memory management.

Implementation of Circular Queue

Below we have the implementation of a circular queue:

1. Initialize the queue, with size of the queue defined (maxSize), and head and tail pointers.

2. enqueue: Check if the number of elements is equal to maxSize - 1:


o If Yes, then return Queue is full.

o If No, then add the new data element to the location of tail pointer and increment
the tail pointer.

3. dequeue: Check if the number of elements in the queue is zero:

o If Yes, then return Queue is empty.

o If No, then increment the head pointer.

4. Finding the size:

o If, tail >= head, size = (tail - head) + 1

o But if, head > tail, then size = maxSize - (head - tail) + 1

De-queues:-
Double ended queue is a more generalized form of queue data structure which allows insertion
and removal of elements from both the ends, i.e , front and back.

Implementation of Double ended Queue

Here we will implement a double ended queue using a circular array. It will have the following
methods:

 push_back : inserts element at back

 push_front : inserts element at front

 pop_back : removes last element

 pop_front : removes first element

 get_back : returns last element

 get_front : returns first element

 empty : returns true if queue is empty

 full : returns true if queue is full


Insert Elements at Front
First we check if the queue is full. If its not full we insert an element at front end by following
the given conditions :
 If the queue is empty then intialize front and rear to 0. Both will point to the first element.

 Else we decrement front and insert the element. Since we are using circular array, we
have to keep in mind that if front is equal to 0 then instead of decreasing it by 1 we make
it equal to SIZE-1.

void Dequeue :: push_front(int key)


{
if(full())
{
cout << "OVERFLOW\n";
}
else
{
//If queue is empty
if(front == -1)
front = rear = 0;

//If front points to the first position element


else if(front == 0)
front = SIZE-1;
else
--front;

arr[front] = key;
}
}

Insert Elements at back


Again we check if the queue is full. If its not full we insert an element at back by following the
given conditions:
 If the queue is empty then intialize front and rear to 0. Both will point to the first element.
 Else we increment rear and insert the element. Since we are using circular array, we have
to keep in mind that if rear is equal to SIZE-1 then instead of increasing it by 1 we make
it equal to 0.

void Dequeue :: push_back(int key)


{
if(full())
{
cout << "OVERFLOW\n";
}
else
{
//If queue is empty
if(front == -1)
front = rear = 0;

//If rear points to the last element


else if(rear == SIZE-1)
rear = 0;

else
++rear;

arr[rear] = key;
}
}

Delete First Element


In order to do this, we first check if the queue is empty. If its not then delete the front element by
following the given conditions :
 If only one element is present we once again make front and rear equal to -1.
 Else we increment front. But we have to keep in mind that if front is equal to SIZE-1 then
instead of increasing it by 1 we make it equal to 0.
void Dequeue :: pop_front()
{
if(empty())
{
cout << "UNDERFLOW\n";
}
else
{
//If only one element is present
if(front == rear)
front = rear = -1;

//If front points to the last element


else if(front == SIZE-1)
front = 0;

else
++front;
}
}

Delete Last Element


Inorder to do this, we again first check if the queue is empty. If its not then we delete the last
element by following the given conditions :
 If only one element is present we make front and rear equal to -1.
 Else we decrement rear. But we have to keep in mind that if rear is equal to 0 then instead
of decreasing it by 1 we make it equal to SIZE-1.
void Dequeue :: pop_back()
{
if(empty())
{
cout << "UNDERFLOW\n";
}
else
{
//If only one element is present
if(front == rear)
front = rear = -1;

//If rear points to the first position element


else if(rear == 0)
rear = SIZE-1;

else
--rear;
}
}

Check if Queue is empty


It can be simply checked by looking where front points to. If front is still intialized with -1, the
queue is empty.

bool Dequeue :: empty()


{
if(front == -1)
return true;
else
return false;
}
Check if Queue is full
Since we are using circular array, we check for following conditions as shown in code to check if
queue is full.

bool Dequeue :: full()


{
if((front == 0 && rear == SIZE-1) ||
(front == rear + 1))
return true;
else
return false;
}

Return First Element


If the queue is not empty then we simply return the value stored in the position which front
points.

int Dequeue :: get_front()


{
if(empty())
{ cout << "f=" <<front << endl;
cout << "UNDERFLOW\n";
return -1;
}
else
{
return arr[front];
}
}

Return Last Element


If the queue is not empty then we simply return the value stored in the position which rear points.

int Dequeue :: get_back()


{
if(empty())
{
cout << "UNDERFLOW\n";
return -1;
}
else
{
return arr[rear];
}
}
Recursion :-
The process in which a function calls itself directly or indirectly is called recursion and the
corresponding function is called as recursive function. Using recursive algorithm, certain
problems can be solved quite easily. Examples of such problems are Towers of Hanoi
(TOH), Inorder/Preorder/Postorder Tree Traversals, DFS of Graph, etc.
OR
C language म, Recursion एक या है िजसम एक function अपने आप को बार-बार call करता है. इस function
को recursive function कहते ह. इस कार क function call को recursive calls कहा जाता है . Recursion म बहु त
सार ं recursive calls होती है इस लए इसको terminate करने के लए terminate condition का योग करना
आव यक होता है .
Recursion को हम सभी problems पर apply नह ं कर सकते पर तु इसका योग करके हम कु छ
problems को आसानी से solve कर सकते ह. उदाहरण के लए – हम इसका योग sorting, searching, traversal
आ द problems को solve करने के लए कर कर सकते ह.
C ो ा मंग ल वेज recursion को सपोट करती है. पर तु इसका योग करने के दौरान programmer को
function म exit condition को define करना आव यक होता है अ यथा यह infinite loop तक चलता रहे गा.
Recursive functions बहु त सार ं mathematical problems को solve करने म बहु त उपयोगी होती है जैसे क – एक
number के factorial को calculate करना, fibonacci series को जनरे ट करना आ द.

Recursion का syntax –
इसका basic syntax नीचे दया गया है :-

void recurse()
{
... .. ...
recurse();
... .. ...
}

int main()
{
... .. ...
recurse();
... .. ...
}
Example − a function calling itself.
int function(int value) {
if(value < 1)
return;
function(value - 1);

printf("%d ",value);
}

Example − a function that calls another function which in turn calls it again.
int function1(int value1) {
if(value1 < 1)
return;
function2(value1 - 1);
printf("%d ",value1);
}
int function2(int value2) {
function1(value2);
}

program – recursion का योग करके एक number के factorial को find करना


#include<stdio.h>

long factorial(int n)
{
if (n == 0)
return 1;
else
return(n * factorial(n-1));
}

void main()
{
int number;
long fact;
printf("Enter a number: ");
scanf("%d", &number);

fact = factorial(number);
printf("Factorial of %d is %ld\n", number, fact);
return 0;
}

Output –
Enter a number : 10
Factorial of 10 is 3628800

ऊपर दए गये program म हमने 10 number को enter कया है और उसका factorial ा त कया.
Advantage of Recursion
1. यह अनाव यक function call को कम करता है.
2. इसके वारा हम problems को आसानी से solve कर सकते है य क iterative solution बहु त बड़ा और
complex (क ठन) होता है .
3. यह हमारे code को elegant (सु ंदर) बना दे ता है .
Disadvantage of Recursion
1. Recursion का योग करके बनाये गये program को समझना और debug करना मु ि कल होता है.
2. इसके लए हम यादा memory space क आव यकता होती है .
3. इसम program को execute करने म यादा समय लगता है.
Types of Recursion
इसके कार न न ल खत ह:-

1:- Tail Recursion – य द एक recursive function खु द को call करता है और यह recursive call, फं शन का


अं तम statement है तो इसे tail रकशन कहते ह. इस recursive call के बाद फं शन कु छ भी perform नह ं करता
है .
2:- single recursion – इस कार के रकशन म केवल एक recursive call होती है.
3:- Multiple recursion – इस कार के रकशन म बहु त सार ं recursive calls होती ह.
4:- indirect recursion – यह रकशन तब घ टत होता है जब एक function दूसरे function को call करता है
िजसके कारण उसे original function को call करना पड़ता है.

You might also like