Presentation is loading. Please wait.

Presentation is loading. Please wait.

A Binary Tree is a tree in which each node has at most 2 children

Similar presentations


Presentation on theme: "A Binary Tree is a tree in which each node has at most 2 children"— Presentation transcript:

1 A Binary Tree is a tree in which each node has at most 2 children
A Binary Tree is a tree in which each node has at most 2 children. (Left child and right child.) a b c d e f g h i A binary tree is full if each node has 0 or 2 children. A full binary tree with i internal vertices has i + 1 terminal vertices and 2i + 1 total vertices.

2 If a binary tree has height h and t terminal vertices
then log2 t < h. ( that is t < 2h ) a b c d e f g h What is the maximum number of leaves a tree of height 3 can have?

3 A binary search tree is a binary tree in which the data stored in its nodes is ordered (usually numerically or alphabetically). The ordering follows the rule that for any node x in the tree, the data in the left subtree < the data in x and the data in the right subtree > the data in x. Joe Pat Gail Ann Hal Zack Kate

4 Is Ike in the tree? Joe Gail Hal In the worst case ( when the item searched for is on the last level or not in the tree), the time needed is approximately equal to the height of the tree. Exactly equal to the greatest integer < log2 (n) where n = total no. of nodes in the full tree of minimal height.

5 Ann Is Tom in the list? Gail Hal Joe Kate Pat Zack

6 A binary tree is balanced if for every vertex v in the tree, the heights of the left and right subtrees differ by at most 1. The more balanced the tree, the more efficient for searching.

7 Preorder (left child); Preorder (right child);}
Pre order Traversal g e i c f h k a d Recursive Procedure: Preorder (root) g e c a d f i h k If root exists, {process data; Preorder (left child); Preorder (right child);}

8 {Inorder (left child); process data; Inorder (right child);} a c d e f
Inorder Traversal g e i c f h k a d Inorder (root) If root exists, {Inorder (left child); process data; Inorder (right child);} a c d e f g h i k

9 {Postorder (left child);
Postorder Traversal g e i c f h k a d Postorder (root) If root exists, {Postorder (left child); process data;} Postorder (right child); a d c f e h k i g

10 Traversing a Tree Preorder Traversal i,f,c,b,e,g,k,j,m
f k c g j m b e Preorder Traversal i,f,c,b,e,g,k,j,m Inorder Traversal b,c,e,f,g,i,j,k,m Postorder Traversal b,e,c,g,f,j,m,k,i


Download ppt "A Binary Tree is a tree in which each node has at most 2 children"

Similar presentations


Ads by Google