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
Which sorting algorithm uses minimum number of swaps?
Explain linear linked implementation of Stack and Queue?
what is the difference between dynamic as well as non - dynamic data structures.
Which sorting algorithm is considered the fastest?
Describe tree database. Explain its common uses.
How are elements stored in hashset?
What is a matrix?
Define hash function?
What is an example of an array?
Does arraylist have a tostring?
Write a Program for Insert in a sorted list
What is data algorithm?
How do I use quick sort?
What are doubly linked lists?
Explain the steps to insert data into a singly linked list?