0

I'm trying to come up with examples of recursive algorithms / functions that cannot be rewritten in a way that avoids using lots of stack memory (i.e. cannot be made fully tail recursive nor rewritten using a loop that doesn't use a stack). Do such functions exist?

I think quicksort might be a candidate, but am not sure if it can be rewritten to use a single tail-recursive function call.

2
  • This question is more appropriate for cs.stackexchange.com Commented Sep 19, 2013 at 4:21
  • 1
    Try Ackermann function. Commented Sep 19, 2013 at 4:44

1 Answer 1

0

Every algorithm that requires more than one call in the general case cannnot be done without a backtrack stack for iteration or growing the stack because the first call is not in tail position and will always have a continuation.

The simple fibonacci, quicksort and sum of tree are all in that category.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.