preorder traversal

(idea) by nbaldwin (?) Sun Nov 14 1999 at 9:06:40
A way of traversing a tree that processes the current node before processing the left and right subtrees. This is a depth-first algorithm, and can be compared to inorder traversal and postorder traversal.

Generally speaking, this is the most useful of the depth-first searches in terms of search, as a node is processed before either subtree is recursively searched.

(idea) by ClockworkGrue (1.1 y) Thu Aug 30 2001 at 22:12:56
Preorder Traversal | Postorder Traversal | Inorder Traversal

  1. Visit the root.
  2. Traverse the left subtree.
  3. Traverse the right subtree.
For those of us who are visual learners, preorder traversal of a binary tree would look something like this.

           A     depth = 0
          / \
         B   D   depth = 1
        /   / \
       C   E   F depth = 2
Y'know, if you log in, you can write something here, or contact authors directly on the site. Create a New User if you don't already have an account.