ple.. briefly describe the purpose of having a base case and
a recursive case in a recursive algorithm
Answer Posted / 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 |
Post New Answer View All Answers
Define quadratic probing?
Where the data structures are used?
What is the best data structure and algorithm to implement cache?
How do you do binary search?
Define static data structures?
Is bucket sort a comparison sort?
What is difference between list and array?
Can tuple be sorted?
Write an algorithm to show the reverse of link list?
Is hashset a collection?
Which interfaces are implemented by linkedlist?
what is the difference between singly and doubly linked lists?
What do you understand by stable sort?
What is frozenset?
What is a string or array type?