Page 1 of 1

N level tree traversing

Posted: Sat Feb 12, 2011 3:29 am
by phpeid
Hello everybody,

i am working on n level category tree structure, for your information the category tree structure image is attached with this post.

Let's consider, each of the category have hundreds( n level ) of category in each, i want to traverse each category without using recursive functions, reason being recursive functions are very slow, is there any way to do this??

Thanks,
phpeid

Re: N level tree traversing

Posted: Sat Feb 12, 2011 7:52 am
by Weirdan
Couple of notes:
  1. Recursive functions are not slow, what could be slow is how you using them. For example, running queries like 'select * from nodes where parent_id=$current_id' is certainly not a good idea in a recursive function.
  2. Your 'tree' is not a tree, since tree is an acyclic graph, while you have cycles in your structure.

Re: N level tree traversing

Posted: Sat Feb 12, 2011 9:49 am
by Darhazer