ple.. briefly describe the purpose of having a base case and
a recursive case in a recursive algorithm

Answers were Sorted based on User's Feedback



ple.. briefly describe the purpose of having a base case and a recursive case in a recursive algori..

Answer / arka

Lets assume factorial function defined recursively:
int fact(int n)
{
if(n==0||n==1)
return(1); //base case
else
return(n*fact(n-1)); //recursive case
}
the necessity for recursive case is simply recursion
whereas the base case is needed to terminate the recursion.
eg:fact(4)=>4*fact(3)=>4*3*fact(2)=>4*3*2*fact(1)=4*3*2*1.
for fact(1) hte base case is satisfied and the function
fact is not called again.

Is This Answer Correct ?    15 Yes 0 No

ple.. briefly describe the purpose of having a base case and a recursive case in a recursive algori..

Answer / baskar

In recursive algorithm.
1. Base case gives the condition for recursive algorithm
when the recursive call is stop.
2.recursive case vice versa.

Is This Answer Correct ?    6 Yes 0 No

Post New Answer

More Data Structures Interview Questions

Q # 1 : in which graph algorithm do we start finding vertices that should be first in the topological order and then apploy the fact that every vertex must come before its successors in the topolgical order.

3 Answers  


List out the disadvantages of using a linked list?

0 Answers  


What is bubble sort used for?

0 Answers  


Tell me what should be done in the base case for this recursive problem?

0 Answers  


Define tree edge?

0 Answers  






Write an algorithm to find middle element in the linked list.

0 Answers   JPMorgan Chase,


What is the impact of signed numbers on the memory?

0 Answers  


What is a Queue? Explain its operation with example?

0 Answers  


Q#1: An algorithm is made up of 2 modules M1 and M2.If order of M1 is F(n) and order of M2 is g (n) then what is the order of the algorithm. Q # 2 : How many binary trees are possible with 3 nodes? with 4 nodes?

4 Answers  


Is it possible to make an array volatile in java?

0 Answers  


What is red black tree in data structure?

0 Answers  


Sorting is not possible by using which of the following methods? (a) Insertion (b) Selection (c) Exchange (d) Deletion

1 Answers  


Categories