Parts of a Tree
Parts of a Tree nodes
Parts of a Tree parent node
Parts of a Tree child nodes parent node
Parts of a Tree child nodes parent node
Parts of a Tree root node
Parts of a Tree leaf nodes
Parts of a Tree sub-tree
Parts of a Tree sub-tree
Parts of a Tree sub-tree
Parts of a Tree sub-tree
Binary Tree Setiap Simpul hanya boleh memiliki paling banyak 2 buah cabang
Traversal Systematic way of visiting all the nodes. (setiap kunjungan hanya mengunjungi tepat satu kali) Methods (metode): Levelorder, Preorder, Inorder, and Postorder They all traverse the left subtree before the right subtree. (kunjungan selalu di mulai dari cabang kiri ke mudian ke cabang kanan)
Level order
Example: level order 43 31 64 20 40 56 89 28 33 47 59
Preorder Traversal Visit the node. Traverse the left subtree. Traverse the right subtree.
Example: Preorder 43 43 31 64 31 64 20 20 40 56 89 40 56 89 28 33 47 59 28 33 47 59
Inorder Traversal Traverse the left subtree. Visit the node. Traverse the right subtree.
Example: Inorder 43 43 31 64 31 64 20 20 40 56 89 40 56 89 28 33 47 59 28 33 47 59
Postorder Traversal Traverse the left subtree. Traverse the right subtree. Visit the node.
Example: Postorder 43 43 31 64 31 64 20 20 40 56 89 40 56 89 28 33 47 59 28 33 47 59
Expression Tree A Binary Tree built with operands and operators. Also known as a parse tree. Used in compilers.
Example: Expression Tree + / / 1 3 * 4 6 7 1/3 + 6*7 / 4
Notation Preorder Inorder Postorder Prefix Notation Infix Notation Postfix Notation
Example: Infix + + / / / / 1 1 3 * 4 3 * 4 6 7 6 7
Example: Postfix 1 + + / / / / 1 3 * 4 3 * 4 6 7 6 7 Recall: Reverse Polish Notation
Example: Prefix + / / 1 3 * 4 6 7 + / 1 3 / * 6 7 4