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


Please Help Members By Posting Answers For Below Questions

Is arraylist synchronized?

538


Is it necessary to sort a file before searching a particular item ?

549


Which is faster quick sort or merge sort?

476


Define general trees?

549


Define red-black trees.

568






Can a hashset contain duplicates?

480


What is the purpose of sorting algorithms?

506


Is array a data structure?

500


Name few concurrent collection classes?

484


Define a Deque?

602


What is bubble insertion selection sort?

482


Complete structure of hashmap, very detail description, along with the basic coding of the hashmap internal implementation.

630


Why insertion is faster in linked list?

453


What is a graph?

583


Which is faster arraylist or linked list?

482