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
How will you check the validity of an expression containing nested parentheses?
How to reverse a singly linked list?
How many times is merge sort called?
What is bubble sort used for?
Why is selection sort used?
How does arraylist size work?
What is difference between list and linked list?
How many links are there in a binary tree of N nodes?
How do we search a specific element in an array?
What is sequential search? What is the average number of comparisons in a sequential search?
What is an algorithm in coding?
What is homogeneous array?
Define binary tree insertion.
What is linear-logarithm chasm?
What are the advantages and disadvantages of copyonwritearraylist?