Ask a Question

1.write with example the concept of \"Tail recursion\". 2.Deduce the time complexity of Tower of Hanoi problem in terms of 0-notation. 3.write an algorithm to multiply two polynomials represented as singly linked lists of non-zero terms. 4.what is Sparse Matrix? Implement a sparse by an efficient data structure and illustrate the implementation by an example.

on 2011-04-27 21:41:54   by nilakshi   on MCA  1 answers

Riya

on 2011-04-29 09:30:00  

The basic idea behind Tail Recursion is to eliminate the storage of any state information across the recursive steps. All information that would ever be needed at any single step is passed as a parameter to the function instead of being stored at some higher level in the recursion stack. This allows the XSL engine to treat the recursive function as though it were an iterative loop in a procedural language. Tail recursion is a condition where you should strongly question the need to use recursion. Specifically it\'s when the recursive call happens at the very END of the function and nothing occurs afterwards. If this is the case, in languages which do not do this for you automatically -- which are most all of them -- you should consider changing the recursive function into a loop. The reason for this is that function calls are more inefficient and use more resources than loops so the ability to recognize tail recursion and code around it is an important consideration in designing your programs.