Re: Inorder Traversal of B-Tree
- From: Logan Shaw <lshaw-usenet@xxxxxxxxxxxxx>
- Date: Mon, 28 Jan 2008 23:37:38 -0600
annamalai wrote:
On Jan 28, 9:12 pm, user923005 <dcor...@xxxxxxxxx> wrote:On Jan 28, 5:20 pm, annamalai <annamalai.gurus...@xxxxxxxxx> wrote:
Can anybody tell me whether an in-order traversal of a B-Tree will
result in the keys being listed in ascending order? I am trying to
find out the correct way to do an inorder traversal of a B-Tree. Any
help much appreciated.
What do you suppose that "inorder" means in terms of traversal?
When you are in doubt, simple things can get confusing.
No doubt. I've experienced that recently myself... :-)
Most of the
discussion about tree traversal talks in terms of node (rather than
the keys). Even the Wikipedia article on Tree_traversal, talks in
terms of node. I guess that is because they are talking about binary
search trees. I am looking for multiway tree traversal, specifically
B-Tree traversal.
Let me then rephrase my question slightly. While traversing a B-Tree,
what does it mean to visit a node? Do I visit only one key, or do I
visit all the keys?
The important thing to understand here is that the answer to your
original question (whether traversing the tree will result in the
keys being listed in ascending order) is *necessarily* "yes".
The reason a B-tree works (and the reason a binary search tree works)
is that the B-tree follows a set of rules, and these rules ensure
that the nodes (and the key or keys within the nodes) are arranged
in such a way that order is preserved. If a node in a B-tree has
two keys, the rules of the B-tree dictate that all of the nodes to
the left of the first key have nothing but smaller keys in them,
that all of the nodes pointed to by the middle pointer have nothing
but keys between the original node's key's values, and that all of
the nodes to the right of the node have keys greater than both the
keys in the original node. A B-tree guarantees this specifically
so that it can keep the nodes in order; if the tree did not capture
the ordering, it wouldn't be possible to do the "divide and conquer"
approach that is what makes B-tree retrieval fast.
So a correct in-order traversal of a B-tree will return the keys in
order, and an implementation of a correct in-order traversal will
be built upon the properties of a B-tree that allow it to keep the
keys in order.
- Logan
.
- Follow-Ups:
- Re: Inorder Traversal of B-Tree
- From: annamalai
- Re: Inorder Traversal of B-Tree
- References:
- Inorder Traversal of B-Tree
- From: annamalai
- Re: Inorder Traversal of B-Tree
- From: user923005
- Re: Inorder Traversal of B-Tree
- From: annamalai
- Inorder Traversal of B-Tree
- Prev by Date: Re: Where do two linked lists merge?
- Next by Date: Between C and Java - which is easier for writing networking software
- Previous by thread: Re: Inorder Traversal of B-Tree
- Next by thread: Re: Inorder Traversal of B-Tree
- Index(es):
Relevant Pages
|