954,498 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Tree traversal

Hi everyone,

I have a question on tree traversal, if I want to find the lowest common ancestor, what kind of traversal can I use? I was thinking of Euler Tour, but does that traversal only restricted to binary tree? because my question does not mention that it is a binary tree.

ahgu00321
Newbie Poster
1 post since Aug 2006
Reputation Points: 10
Solved Threads: 0
 

It depends on how your tree is structured. Do leaf nodes contain pointers to their parents? Or is it that parents contain pointers to their children, and that you're only given the root node and the addresses of the two particular leaf nodes? In the former case, you can do this in O(h) time with constant memory usage.

Rashakil Fol
Super Senior Demiposter
Team Colleague
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 177
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You