SLIDE 12 12
SDA/ TREE/ V2.0/ 45
Properties of binary tree (cont.)
Complete binary tree with n nodes can be shown by
using an array, then for any node with index i, we have:
Parent (i) is at ⎣i/2⎦ if i ≠1; for i =1, we have no parent. Left-child (i ) is at 2i if 2i ≤ n. (else no left-child) Right-child (i ) is at 2i+1 if 2i +1 ≤ n (else no right-child)
SDA/ TREE/ V2.0/ 46
Summary
Tree, Binary Tree In order to process the elements of a tree, we consider
accessing the elements in certain order
Tree traversal is a tree operation that involves "visiting” (or"
processing") all the nodes in a tree.
Depth First Search (DFS): Pre-order: Visit node first, pre-order all its subtrees from leftmost
to rightmost.
Inorder: Inorder the node in left subtree and then visit the root
following by inorder traversal of all its right subtrees.
Post-order: Post-order the node in left subtree and then post-
- rder the right subtrees followed by visit to the node.
Breadth First Search (BFS): Level-order : Visit root followed by its children from left to right
and followed by their children. So we go down the tree level by level.
SDA/ TREE/ V2.0/ 47
Further Reading
http://telaga.cs.ui.ac.id/WebKuliah/IKI101
00/1998/handout/handout10.html
http://telaga.cs.ui.ac.id/WebKuliah/IKI101
00/1998/handout/handout15.html
Chapter 17
SDA/ TREE/ V2.0/ 48
What’s Next
Binary Search Tree