Preorder and Postorder Traversal of Rooted Trees

Requires a Wolfram Notebook System

Interact on desktop, mobile and cloud with the free Wolfram CDF Player or other Wolfram Language products.

Requires a Wolfram Notebook System

Edit on desktop, mobile and cloud with any Wolfram Language product.

Many algorithms that make use of trees often traverse the tree in some order, that is, they visit each vertex in a systematic way. Two commonly used traversals are preorder and postorder. A preorder traversal of is defined by a two-step recursion:

[more]

1. visit the root and

2. visit in preorder the subtrees of the root of from left to right.

A postorder is similarly defined as:

1. visit in postorder the subtrees of from left to right and

2. visit the root.

This Demonstration shows the preorder and postorder traversals corresponding to a randomly labeled rooted tree with a chosen number of vertices.

[less]

Contributed by: Jaime Rangel-Mondragon (August 2011)
Open content licensed under CC BY-NC-SA


Snapshots


Details



Feedback (field required)
Email (field required) Name
Occupation Organization
Note: Your message & contact information may be shared with the author of any specific Demonstration for which you give feedback.
Send