English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I can't figure out the algorithm to traverse a BST non-recursively. I know it involves a Stack, but I can't figure out where to go from there without using recursion. Help? I'm looking especially for one in somewhat specific pseudo-code - specifically I'm implementing this in Java.

2006-10-06 17:15:22 · 5 answers · asked by Anonymous 3 in Computers & Internet Programming & Design

I didn't ask for your advice on what to use, I asked for a non-recursive algorithm. Specifically, it's because there's something added into this assignment to force you to use a non-recursive algorithm.

2006-10-06 17:20:28 · update #1

The algorithm isn't the assignment, it's just required to continue the assignment. Everyone else has one from a previous assignment to copy/paste, I missed that day.

2006-10-06 17:31:31 · update #2

5 answers

notes emailed to you

2006-10-06 17:34:48 · answer #1 · answered by 987654321abc 5 · 1 2

Since this looks like homework, I can't give the full answer, but I can give you a hint:

1. Try implementing the algorithm recursively.
2. Now try tracing some executions out by hand.
3. You'll see the execution stack change.
4. Try to derive your algorithm from step 3.

2006-10-07 00:26:17 · answer #2 · answered by avocaronico 3 · 0 1

Recursion is nothing more than a stack mechanism. So, why not use it? It makes the code more obvious.

2006-10-07 00:19:16 · answer #3 · answered by Anonymous · 0 2

D.Knuth, "The Art of the Computer Programming". Detailed explanation.

2006-10-07 01:43:30 · answer #4 · answered by alakit013 5 · 0 1

Answer: $1.98

2006-10-07 00:23:47 · answer #5 · answered by Anonymous · 0 2

fedest.com, questions and answers