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 primary clustering?
Which language is best for data structures and algorithms?
What is stable sort?
Define probing?
Does treeset allow duplicates?
What is difference between data type and data structure?
What is a treemap chart?
What do you mean by rehashing?
Which is the simplest file structure?
Explain the common uses of threaded binary tree.
What is impact of signed numbers on the memory?
What do you know about the big-o notation and can you give some examples with respect to different data structures?
Which is the parent class of enumset class?
Write a Program for Insert in a sorted list
How many types of linked list exist?