Discrete Mathematics University of Kentucky CS 275 Spring ... - MGNet
Discrete Mathematics University of Kentucky CS 275 Spring ... - MGNet
Discrete Mathematics University of Kentucky CS 275 Spring ... - MGNet
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Example: Given a tree T = (V,E) with keys ordered 0 < 1 < 1.1 < 2 < 2.1 < 2.2 <<br />
2.2.1 < 2.3, we represent it as<br />
• 0<br />
• 1 • 2<br />
• 1.1 • 2.1 • 2.2 • 2.3<br />
• 2.2.1<br />
We will use this example for quite some time.<br />
199<br />
Definition (Preorder Traversal): Let T be an ordered rooted tree with root r. If T<br />
consists only <strong>of</strong> r, then r is the preorder traversal <strong>of</strong> T. Otherwise, suppose T 1 ,<br />
T 2 , …, T n are subtrees at r from left to right in T. Then the preorder traversal<br />
begins at r and continues by traversing T 1 in preorder, T 2 in preorder, …, and T n<br />
in preorder.<br />
Example: In the tree example at the top <strong>of</strong> page 199, the preorder traversal order<br />
is 0, 1, 1.1, 2, 2.1, 2.2, 2.2.1, and 2.3.<br />
Definition (Inorder Traversal): Let T be an ordered rooted tree with root r. If T<br />
consists only <strong>of</strong> r, then r is the inorder traversal <strong>of</strong> T. Otherwise, suppose T 1 , T 2 ,<br />
…, T n are subtrees at r from left to right in T. Then the inorder traversal begins<br />
by traversing T 1 in inorder, then r, and continues with T 2 in inorder, …, and T n<br />
in inorder.<br />
Example: In the tree example at the top <strong>of</strong> page 199, the inorder traversal order<br />
is 1.1, 1, 0, 2.1, 2, 2.2.1, 2.2, and 2.3.<br />
200