Preoder traversal of a Btree

Posted by Phenom on Stack Overflow See other posts from Stack Overflow or by Phenom
Published on 2010-05-11T02:25:10Z Indexed on 2010/05/11 2:44 UTC
Read the original article Hit count: 383

Filed under:
|

I'm trying to figure out how to do a preorder traversal of a Btree. I know that generally preorder traversal works like this:

preorder(node)
{
print value in node
preorder(left child)
preorder(right child)
}

What's confusing to me is how to make this work with a Btree, since in each node there are multiple values and multiple child pointers. When printing values, do all the values in the node get printed before descending into the left child?

Each node looks like this:

child1 value1 child2 value2 child3 value3 child4

Also, why would anyone want to do a preorder traversal of a Btree, since an inorder traversal is what will display the values in ascending order?

© Stack Overflow or respective owner

Related posts about btree

Related posts about traversal