top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the data structures used to perform recursion?

+3 votes
685 views
What is the data structures used to perform recursion?
posted Apr 24, 2015 by Vrije Mani Upadhyay

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
 
Best answer

Stack. Because of its LIFO (Last In First Out) property it remembers its 'caller' so knows whom to return when the function has to return. Recursion makes use of system stack for storing the return addresses of the function calls.

Every recursive function has its equivalent iterative (non-recursive) function. Even when such equivalent iterative procedures are written, explicit stack is to be used.

answer Apr 27, 2015 by Mohammed Hussain
Similar Questions
+6 votes

I was trying to get maximum rectangle area for a given histogram but I used brute force approach which have O(n^2) time complexity so I want some better solution using stack so that we could reduce time complexity to O(n) or O(log n ).

...