Data Structures and Algorithms with Object-Oriented Design Patterns in C#
next up previous contents index

Inorder Traversal

Whereas inorder traversal of an N-ary tree is not defined for N>2, inorder traversal is defined for an M-way search tree: By definition, the inorder traversal of a search tree visits all the keys contained in the search tree in order.

Program gif is an implementation of the algorithm for depth-first traversal of an M-way search tree given in Section gif. The keys contained in a given node are visited (by calling the InVisit method of the visitor) in between the appropriate subtrees of that node. That is, key tex2html_wrap_inline63523 is visited in between subtrees tex2html_wrap_inline63521 and tex2html_wrap_inline62605.

   program20836
Program: MWayTree class DepthFirstTraversal method.

In addition, the PostVisit method is called on tex2html_wrap_inline64559 after subtree tex2html_wrap_inline63521 has been visited, and the PreVisit method is called on tex2html_wrap_inline64563 before subtree tex2html_wrap_inline62605 is visited.

It is clear that the amount of work done at each node during the course of a depth-first traversal is proportional to the number of keys contained in that node. Therefore, the total running time for the depth-first traversal is tex2html_wrap_inline64567, where K is the number of keys contained in the search tree.


next up previous contents index

Bruno Copyright © 2001 by Bruno R. Preiss, P.Eng. All rights reserved.