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

What is the difference between array and stack?

0 Answers  


What is top in stack?

0 Answers  


What are different techniques for making hash function?

0 Answers  


Can we store primitives in collections?

0 Answers  


Is it possible to store null key and null values in a hashmap?

0 Answers  


What is dynamic array in excel?

0 Answers  


What do you mean by data types?

0 Answers  


Can treeset contain null?

0 Answers  


Does treemap sort on key or value?

0 Answers  


How many types of linked list are there?

0 Answers  


What is structured data with example?

0 Answers  


Differentiate between singly and doubly linked lists?

0 Answers  


Categories