Professional Documents
Culture Documents
1
Binary Search Tree
3
Binary Search Tree
4
Binary Search Tree
Determining the Number of External Nodes:
Number of external nodes = Total External Nodes(left sub–
tree) + Total External Nodes (right sub– tree)
5
Binary Search Tree
6
Binary Search Tree - BST
Finding the Smallest Node in a BST:
- The value of the leftmost node of the left sub-tree
- If left sub-tree is NULL, then value of root node (smallest)
7
Binary Search Tree - BST
Finding the Largest Node in a BST:
8
Binary Search Tree
Deleting a Binary Search Tree:
To delete/remove an entire BST from the memory.
9
Threaded Binary Tree
- Same as BT but difference in storing NULL pointers.
- to avoid the NULL value the threads are used.
11
Threaded Binary Tree
Create Threaded Binary Tree: NULL pointers are avoided,
instead, left NULL ptr --- > inorder predecessor and
right NULL ptr --- > inorder successor
- 2 additional nodes lth & rth – dummy nodes, indicates
thread is present or not.
If thread exists, set lth or rth = 1 else 0.
12
Create Threaded Binary Tree
Example : 10, 20, 30, 40, 50
13
Create Threaded Binary Tree
Example : 10, 20, 30, 40, 50
14
Create Threaded Binary Tree
Example : 10, 20, 30, 40, 50
15
Threaded Binary Tree
- Types:
- 1. One-way threaded tree 2. Two way threaded tree
1-way threaded tree: single-threaded tree or left-threaded BT
- If the thread appears in the left field, then the left field will
be made to point to the in-order predecessor of the node.
2-way threaded tree: right threaded BT or double-threaded
tree or fully threaded binary tree.
- threads will appear in both the left and the right field of the
node.
- If the thread appears in the right field, then it will point to the
in-order successor of the node.
16
Linked representation Binary Tree
17
Linked representation Binary Tree
18
Linked representation Binary Tree
19
Threaded Binary Tree
Advantages TBT:
- Wastage of memory utilized using threads
- Predecessor & successor of any node accessed effectively
Disadvantages:
- Insertion and deletion of nodes – complex and link
manipulation is required (insertion).
20
Threaded Binary Tree
21
THANK YOU
22