Professional Documents
Culture Documents
Objectives
Ver. 1.0
Session 13
Directory structure Consider a scenario where you are required to represent the directory structure of your operating system. The directory structure contains various folders and files. A folder may further contain any number of sub folders and files. In such a case, it is not possible to represent the structure linearly because all the items have a hierarchical relationship among themselves. In such a case, it would be good if you have a data structure that enables you to store your data in a nonlinear fashion.
Ver. 1.0
Session 13
A tree are is a used nonlinear data structure that represent a between Trees in applications in which the relation hierarchical relationship among the various elements. data elements needs to be represented in adata hierarchy.
J L
K M
Ver. 1.0
Session 13
Each The topmost element node in a tree in a tree is referred is called to root. as a node.
root A
J L
K M node
Ver. 1.0
Session 13
Each node in a tree can further have subtrees below its hierarchy.
root A
J L
K M node
Ver. 1.0
Session 13
Leaf node : It refers to a node with nomost children. Let us discuss various terms that are frequently used with trees.
J L
K M
Ver. 1.0
Session 13
Subtree: A of a tree, which can be viewed a are Children ofportion a node : The roots of the subtrees of aas node separate in itself is called called thetree children of the node.a subtree.
A subtree can also contain just one node called the leaf node.
A
E, F, with G, and HB, are Tree root children of nodes node B. containing E,B F, is the parent these of G, and H is aof subtree nodes. node A. K L M
Ver. 1.0
Session 13
Degree a from node : It refers number ofis subtrees Edge : A of link the parentto tothe a child node referredof toa as node in a tree. an edge.
B Edge
E F G H
Ver. 1.0
Session 13
Nodes B, C, and D are siblings of each other. Nodes E, F, G, and H are siblings of each other. K L M
Ver. 1.0
Session 13
Internal : It: refers to to any node between the rootof and a Level of node a node It refers the distance (in number leaf node. nodes) of a node from the root. Root always lies at level 0.
As you move down the tree, the level increases by one. A
Level 0
J L
K M
Level 2
Level 3
Ver. 1.0
Session 13
Level 1
J L
K M
Level 2
Level 3
Ver. 1.0
Session 13
Consider the following tree and answer the questions that follow:
a. b. c. d. e. f. g. What is the depth of the tree? Which nodes are children of node B? Which node is the parent of node F? What is the level of node E? Which nodes are the siblings of node H? Which nodes are the siblings of node D? Which nodes are leaf nodes?
root
A
B
E I F
C
G
D H
Ver. 1.0
Session 13
Answer:
a. b. c. d. e. f. g. 4 D and E C 2 H does not have any siblings The only sibling of D is E F, G, H, and I
Ver. 1.0
Session 13
Binary is a specific type of tree in which each node can Strictly tree binary tree: have at most two namely child and child. A binary tree in children which every node, left except for the right leaf nodes, hasare non-empty and of right children. There variousleft types binary trees:
Strictly binary tree Full binary tree Complete binary tree
Ver. 1.0
Session 13
Full binary tree: d A binary tree of depth d that contains exactly 2 1 nodes.
A
Ver. 1.0
Session 13
B
4 5
C
6 3
B
4 5
C
3
B
4
C
5
Ver. 1.0
Session 13
[2]
If there are n nodes in a binary tree, then for with index elements of any an node array. i, where 0 < i < n 1: Parent of i is at (i 1)/2. Left child of i is at 2i + 1: If 2i + 1 > n 1, then the node does not have a left child. Right child of i is at 2i + 2: If 2i + 2 > n 1, then the node does have a right child.
3
D
4
E
5
F
6
G
F
G
[5]
[6]
Binary Tree
Array Representation
Ver. 1.0
Session 13
If a node does not have a left child or a right child or both, the respective left or right child fields of that node point to NULL.
Data
Node
Ver. 1.0
Session 13
52
.
68
52
.
.
68
36
.
72
24
36
24
59 70
59
.
.
70
72
.
80
80
Binary Tree
Linked Representation
Ver. 1.0
Session 13
You can implement various operations on a binary tree. A common operation on a binary tree is traversal. Traversal refers to the process of visiting all the nodes of a binary tree once. There are three ways for traversing a binary tree:
Inorder traversal Preorder traversal Postorder traversal
Ver. 1.0
Session 13
Ver. 1.0
Session 13
B is is not not NULL. NULL. The left subtree of node A D to traverse the left Therefore, move to node B B. subtree of A.
root A
Ver. 1.0
I
Session 13
D
Ver. 1.0
I
Session 13
Right subtree of D is not NULL Therefore, move to the right subtree of node D
root A
D
Ver. 1.0
I
Session 13
D
Ver. 1.0
H
Session 13
D
Ver. 1.0
H
Session 13
D
Ver. 1.0
B
Session 13
D
Ver. 1.0
B
Session 13
D
Ver. 1.0
E
Session 13
D
Ver. 1.0
E
Session 13
D
Ver. 1.0
A
Session 13
D
Ver. 1.0
A
Session 13
D
Ver. 1.0
A
Session 13
D
Ver. 1.0
F
Session 13
D
Ver. 1.0
F
Session 13
The left subtree of node C has been visited. Therefore, visit node C.
root A
D
Ver. 1.0
C
Session 13
Right subtree of C is not empty. Therefore, move to the right subtree of node C.
root A
D
Ver. 1.0
C
Session 13
Left subtree of G is not empty. Therefore, move to the left subtree of node G.
root A
D
Ver. 1.0
C
Session 13
D
Ver. 1.0
I
Session 13
D
Ver. 1.0
I
Session 13
Visit node G.
root A
D
Ver. 1.0
G
Session 13
root A
Traversal complete
G
D
Ver. 1.0
G
Session 13
Ver. 1.0
Session 13
Preorder Traversal:
A B D H E C F
Ver. 1.0
Session 13
Ver. 1.0
Session 13
Postorder Traversal: H D E B F
Ver. 1.0
G C A
Session 13
In _________ traversal method, root is processed before traversing the left and right subtrees.
Answer:
Preorder
Ver. 1.0
Session 13
Consider a scenario. SysCall Ltd. is a cellular phone company with millions of customers spread across the world. Each customer is assigned a unique identification number (id). Individual customer records can be accessed by referring to the respective id. These ids need to be stored in a sorted manner in such a way so that you can perform various transactions, such as retrieval, insertion, and deletion, easily.
Ver. 1.0
Session 13
Which datayou structure will you use to the id of the Therefore, need to implement a store data structure that customers? provides the advantages of both arrays as well as linked lists. Can you implement an array? Search operation in an array is fast. A binary search tree combines the advantages of both However, insertion arrays and linked lists. and deletion in an array is complex in nature.
In this case, the total number of customer ids to be stored is very large. Therefore, insertion and deletion will be very time consuming.
Ver. 1.0
Session 13
The following an is example of a binary search tree. Binary search is tree a binary tree in which every node satisfies the following conditions:
All values in the left subtree of a node are less than the value 52 of the node. All values in the right subtree of a node are greater than the value of the 36 node. 68
24
44
59
72
40
55
Ver. 1.0
Session 13
Ver. 1.0
Session 13
Search operation refers value, to the you process of searching for a To search for a specific need to perform the specified steps: value in the tree. following
1. 2. Make currentNode point to the root node If currentNode is null:
a. b. Display Not Found Exit
3.
Compare the value to be searched with the value of currentNode. Depending on the result of the comparison, there can be three possibilities:
a. If the value is equal to the value of currentNode:
i. ii. Display Found Exit Make currentNode point to its left child Go to step 2 Make currentNode point to its right child Go to step 2
b.
c.
Ver. 1.0
Session 13
In a binary search tree, all the values in the left subtree of a node are _______ than the value of the node.
Answer:
smaller
Ver. 1.0
Session 13
Before inserting a node in a the binary search you firstto be Write an algorithm to locate position of tree, a new node need to check whether the tree. tree is empty or not. inserted in a binary search If the tree is empty, make the new node as root. If the tree is not empty, you need to locate the appropriate position for the new node to be inserted. This requires you to locate the parent of the new node to be inserted. Once the parent is located, the new node is inserted as the left child or right child of the parent. To locate the parent of the new node to be inserted, you need to implement a search operation in the tree.
Ver. 1.0
Session 13
2. 3.
4. 5.
52
.
24
36
.
59
68
.
.
72
6.
If the value of the new node is greater than that of currentNode: a. Make currentNode point to its right child
.
80
.
Ver. 1.0
70
Session 13
Refer to the algorithm to locate the parent of the new node to be inserted.
root
2. 3.
4. 5.
52
.
24
36
.
59
68
.
.
72
6.
If the value of the new node is greater than that of currentNode: a. Make currentNode point to its right child
.
80
.
Ver. 1.0
70
Session 13
2. 3.
root currentNode
4. 5.
52
.
24
36
.
59
68
.
.
72
6.
If the value of the new node is greater than that of currentNode: a. Make currentNode point to its right child
.
80
.
Ver. 1.0
70
Session 13
2. 3.
root
4. 5.
52
.
24
36
.
59
68
.
.
72
6.
If the value of the new node is greater than that of currentNode: a. Make currentNode point to its right child
.
80
.
Ver. 1.0
70
Session 13
2. 3.
root
4. 5.
52
.
24
36
.
59
68
.
.
72
6.
If the value of the new node is greater than that of currentNode: a. Make currentNode point to its right child
.
80
.
Ver. 1.0
70
Session 13
2. 3.
root
4. 5.
52
.
24
36
.
59
68
.
.
72
6.
If the value of the new node is greater than that of currentNode: a. Make currentNode point to its right child
.
80
.
Ver. 1.0
70
Session 13
2. 3.
55 > 52
parent currentNode root
4. 5.
52
.
24
36
.
59
68
.
.
72
6.
If the value of the new node is greater than that of currentNode: a. Make currentNode point to its right child
.
80
.
Ver. 1.0
70
Session 13
2. 3.
55 > 52
parent currentNode root
4. 5.
52
.
24
36
.
59
68
.
.
72
6.
If the value of the new node is greater than that of currentNode: a. Make currentNode point to its right child
.
80
.
Ver. 1.0
70
Session 13
2. 3.
55 > 52
parent currentNode root
4. 5.
52
.
currentNode
.
24
36
.
59
68
.
.
72
If the value of the new node is greater than that of currentNode: a. Make currentNode point to its right child
.
80
.
Ver. 1.0
70
Session 13
2. 3.
parent
root
4. 5.
52
.
currentNode
.
24
36
.
59
68
.
.
72
If the value of the new node is greater than that of currentNode: a. Make currentNode point to its right child
.
80
.
Ver. 1.0
70
Session 13
2. 3.
parent
root
4. 5.
52
.
currentNode
parent
.
24
36
.
59
68
.
.
72
If the value of the new node is greater than that of currentNode: a. Make currentNode point to its right child
.
80
.
Ver. 1.0
70
Session 13
2. 3.
55 < 68
root
4. 5.
52
.
currentNode
parent
.
24
36
.
59
68
.
.
72
If the value of the new node is greater than that of currentNode: a. Make currentNode point to its right child
.
80
.
Ver. 1.0
70
Session 13
2. 3.
55 < 68
root
4. 5.
52
.
currentNode
parent
.
24
36
.
59
68
.
.
72
If the value of the new node is greater than that of currentNode: a. Make currentNode point to its right child
.
80
currentNode
.
Ver. 1.0
70
Session 13
2. 3.
root
4. 5.
52
parent
.
24
36
.
59
68
.
.
72
6.
If the value of the new node is greater than that of currentNode: a. Make currentNode point to its right child
.
80
currentNode
.
Ver. 1.0
70
Session 13
2. 3.
root
4. 5.
52
parent
.
24
36 parent 59 currentNode
68
.
.
72
6.
If the value of the new node is greater than that of currentNode: a. Make currentNode point to its right child
.
80
.
Ver. 1.0
70
Session 13
2. 3.
55 < 59
root
4. 5.
52
.
24
36 parent 59 currentNode
68
.
.
72
6.
If the value of the new node is greater than that of currentNode: a. Make currentNode point to its right child
.
80
.
Ver. 1.0
70
Session 13
2. 3.
55 < 59
root
4. 5.
52
.
24
36 parent 59
68
.
.
72
6.
If the value of the new node is greater than that of currentNode: a. Make currentNode point to its right child
.
80
70
Ver. 1.0
Session 13
2. 3.
root
4. 5.
52
.
24
36 parent 59
68
.
.
72
6.
If the value of the new node is greater than that of currentNode: a. Make currentNode point to its right child
.
80
currentNode = NULL
70
Ver. 1.0
Session 13
Once the parent of the new node is located, you can insert the node as the child of its parent.
root
2. 3.
4. 5.
52
.
24
36 parent 59
68
.
.
72
6.
If the value of the new node is greater than that of currentNode: a. Make currentNode point to its right child
.
80
currentNode = NULL
70
Ver. 1.0
Session 13
Ver. 1.0
Session 13
4.
root
5.
.
.
24 36
52
.
.
68
6.
If the value in the data field of new node is less than that of parent: a. Make the left child of parent point to the new node Exit
59
.
.
70
72
.
7.
b.
If the value in the data field of the new node is greater than that of the parent: a. b. Make the right child of parent point to the new node Exit Session 13
80
Ver. 1.0
4.
root
5.
.
.
24 36
52
.
.
68
6.
If the value in the data field of new node is less than that of parent: a. Make the left child of parent point to the new node Exit
59
.
.
70
72
.
7.
b.
If the value in the data field of the new node is greater than that of the parent: a. b. Make the right child of parent point to the new node Exit Session 13
80
Ver. 1.0
4.
root
5.
.
.
24 36
52
.
.
68
6.
If the value in the data field of new node is less than that of parent: a. Make the left child of parent point to the new node Exit
59
.
.
70
72
.
7.
b.
If the value in the data field of the new node is greater than that of the parent: a. b. Make the right child of parent point to the new node Exit Session 13
55
80
Ver. 1.0
4.
root
5.
.
.
24 36
52
.
.
68
6.
If the value in the data field of new node is less than that of parent: a. Make the left child of parent point to the new node Exit
59
.
.
70
72
.
7.
b.
If the value in the data field of the new node is greater than that of the parent: a. b. Make the right child of parent point to the new node Exit Session 13
55
80
Ver. 1.0
4.
root
5.
.
.
24 36
52
.
.
68
6.
If the value in the data field of new node is less than that of parent: a. Make the left child of parent point to the new node Exit
parent 59
.
.
70
72
.
7.
b.
If the value in the data field of the new node is greater than that of the parent: a. b. Make the right child of parent point to the new node Exit Session 13
55
80
Ver. 1.0
4.
root
5.
.
.
24 36
52
.
.
68
6.
If the value in the data field of new node is less than that of parent: a. Make the left child of parent point to the new node Exit
parent 59
.
.
70
72
.
7.
b.
If the value in the data field of the new node is greater than that of the parent: a. b. Make the right child of parent point to the new node Exit Session 13
55
80
Ver. 1.0
4.
root
5.
.
.
24 36
52
.
.
68
6.
If the value in the data field of new node is less than that of parent: a. Make the left child of parent point to the new node Exit
parent 59
.
.
70
72
.
7.
b.
If the value in the data field of the new node is greater than that of the parent: a. b. Make the right child of parent point to the new node Exit Session 13
55
80
Ver. 1.0
4.
root
5.
.
.
24 36
52
.
.
68
6.
If the value in the data field of new node is less than that of parent: a. Make the left child of parent point to the new node Exit
parent
.
55
59
.
.
70
72
.
7.
b.
If the value in the data field of the new node is greater than that of the parent: a. b. Make the right child of parent point to the new node Exit Session 13
80
Ver. 1.0
4.
root
5.
.
.
24 36
52
.
.
68
6.
If the value in the data field of new node is less than that of parent: a. Make the left child of parent point to the new node Exit
parent 59
.
.
70
72
.
7.
b.
If the value in the data field of the new node is greater than that of the parent: a. b. Make the right child of parent point to the new node Exit Session 13
55
80
Delete operation into a locate binary the search tree refers to theto Write an algorithm position of the node process from of deleting the specified node from the tree. deleted a binary search tree. Before implementing a delete operation, you first need to locate the position of the node to be deleted and its parent. To locate the position of the node to be deleted and its parent, you need to implement a search operation.
Ver. 1.0
Session 13
2. 3.
. .
24 36
52
. .
59 68
b.
. .
72
.
80
c.
If the value to be deleted is greater than that of currentNode: i. Make currentNode point to its right child.
.
69
Ver. 1.0
70
Session 13
2. 3.
currentNode
52
. .
59 68
b.
.
24
36
. .
72
.
80
c.
If the value to be deleted is greater than that of currentNode: i. Make currentNode point to its right child.
.
69
Ver. 1.0
70
Session 13
2. 3.
52
. .
59 68
b.
.
24
36
. .
72
.
80
c.
If the value to be deleted is greater than that of currentNode: i. Make currentNode point to its right child.
.
69
Ver. 1.0
70
Session 13
2. 3.
52
. .
59 68
b.
.
24
36
. .
72
.
80
c.
If the value to be deleted is greater than that of currentNode: i. Make currentNode point to its right child.
.
69
Ver. 1.0
70
Session 13
2. 3.
52
parent
b.
.
24
36
.
59
68
. .
72
.
80
c.
If the value to be deleted is greater than that of currentNode: i. Make currentNode point to its right child.
.
69
Ver. 1.0
70
Session 13
2. 3.
52
parent
b.
.
24
36
.
59
68
. .
70 > 52
72
.
80
c.
If the value to be deleted is greater than that of currentNode: i. Make currentNode point to its right child.
.
69
Ver. 1.0
70
Session 13
2. 3.
52
parent
b.
.
24
36
.
59
68
. .
70 > 52
72
.
80
c.
If the value to be deleted is greater than that of currentNode: i. Make currentNode point to its right child.
.
69
Ver. 1.0
70
Session 13
2. 3.
52
parent
currentNode
b.
.
24
36
.
59
68
. .
70 > 52
72
.
80
c.
If the value to be deleted is greater than that of currentNode: i. Make currentNode point to its right child.
.
69
Ver. 1.0
70
Session 13
2. 3.
. .
24 36
52
parent
currentNode
b.
.
59
68
. .
72
.
80
c.
If the value to be deleted is greater than that of currentNode: i. Make currentNode point to its right child.
.
69
Ver. 1.0
70
Session 13
2. 3.
. .
24 36
52
parent
currentNode
b.
parent
68
. .
72
59
.
80
c.
If the value to be deleted is greater than that of currentNode: i. Make currentNode point to its right child.
.
69
Ver. 1.0
70
Session 13
2. 3.
. .
24 36
52
. .
70 > 68
currentNode
b.
parent
68
. .
72
59
.
80
c.
If the value to be deleted is greater than that of currentNode: i. Make currentNode point to its right child.
.
69
Ver. 1.0
70
Session 13
2. 3.
. .
24 36
52
. .
70 > 68
currentNode
b.
parent
68
. .
72
59
.
80
c.
If the value to be deleted is greater than that of currentNode: i. Make currentNode point to its right child.
.
69
Ver. 1.0
70
Session 13
2. 3.
. .
24 36
52
. .
70 > 68
currentNode
b.
parent
68
.
currentNode
59
. .
70
72
.
80
c.
If the value to be deleted is greater than that of currentNode: i. Make currentNode point to its right child.
69
Ver. 1.0
Session 13
2. 3.
. .
24 36
52
. .
68
b.
parent
.
currentNode
59
. .
70
72
.
80
c.
If the value to be deleted is greater than that of currentNode: i. Make currentNode point to its right child.
69
Ver. 1.0
Session 13
2. 3.
. .
24 36
52
. .
68
b.
parent
.
currentNode
59
. .
70
72
.
80
c.
If the value to be deleted is greater than that of currentNode: i. Make currentNode point to its right child.
parent
69
Ver. 1.0
Session 13
2. 3.
. .
24 36
52
. .
59 68
70 < 72
b.
.
currentNode
. .
70
72
.
80
c.
If the value to be deleted is greater than that of currentNode: i. Make currentNode point to its right child.
parent
69
Ver. 1.0
Session 13
2. 3.
. .
24 36
52
. .
59 68
70 < 72
b.
.
currentNode
. .
70
72
.
80
c.
If the value to be deleted is greater than that of currentNode: i. Make currentNode point to its right child.
parent
currentNode 69
Ver. 1.0
Session 13
2. 3.
. .
24 36
52
. .
59 68
b.
. .
72
.
80
c.
If the value to be deleted is greater than that of currentNode: i. Make currentNode point to its right child.
Nodes located
69
Ver. 1.0
parent 70
currentNode
Session 13
Ver. 1.0
Session 13
Ver. 1.0
Session 13
Delete node Algorithm to delete 69 a leaf node from the binary tree.
2.
.
.
24 36
52
.
.
59 68
. .
72
a.
b.
.
80
4.
If currentNode is right child of parent: a. Make right child field of parent point to NULL. Go to step 5.
.
69
b.
70
5.
Ver. 1.0
Session 13
Delete node 69
2.
.
.
24 36
52
.
.
59 68
. .
72
a.
b.
.
80
4.
If currentNode is right child of parent: a. Make right child field of parent point to NULL. Go to step 5.
.
69 currentNode
Ver. 1.0
b.
70 parent
5.
Session 13
Delete node 69
2.
.
.
24 36
52
.
.
59 68
. .
72
a.
b.
.
80
4.
If currentNode is right child of parent: a. Make right child field of parent point to NULL. Go to step 5.
.
69 currentNode
Ver. 1.0
b.
70 parent
5.
Session 13
Delete node 69
2.
.
.
24 36
52
.
.
59 68
. .
72
a.
b.
.
80
4.
If currentNode is right child of parent: a. Make right child field of parent point to NULL. Go to step 5.
.
69 currentNode
Ver. 1.0
b.
70 parent
5.
Session 13
Delete node 69
2.
.
.
24 36
52
.
.
59 68
. .
72
a.
b.
.
80
4.
If currentNode is right child of parent: a. Make right child field of parent point to NULL. Go to step 5.
.
69 currentNode
Ver. 1.0
b.
70 parent
5.
Session 13
Delete node 69
2.
.
.
24 36
52
.
.
59 68
. .
72
a.
b.
.
80
4.
If currentNode is right child of parent: a. Make right child field of parent point to NULL. Go to step 5.
.
69 currentNode
Ver. 1.0
b.
70 parent
5.
Session 13
Delete node 69
2.
.
.
24 36
52
.
.
59 68
. .
72
a.
b.
.
80
4.
If currentNode is right child of parent: a. Make right child field of parent point to NULL. Go to step 5.
.
69 currentNode
Ver. 1.0
b.
70 parent
5.
Write an algorithm to delete a node, which has one child from a binary search tree.
Ver. 1.0
Session 13
2.
. .
24 36
52
.
3.
.
59
68
.
4.
.
70
72
.
5.
.
75
80
6.
7.
Ver. 1.0
Delete node 80
2.
root
. .
24 36
52
.
3.
.
59
68
.
parent
4.
.
70
72
.
currentNode 5.
.
75
80
6.
7.
Ver. 1.0
Delete node 80
2.
root
. .
24 36
52
.
3.
.
59
68
.
parent
4.
.
70
72
.
currentNode 5.
.
75
80
6.
7.
Ver. 1.0
Delete node 80
2.
root
. .
24 36
52
.
3.
.
59
68
.
parent
4.
.
70
72
.
currentNode 5.
.
75 child
80
6.
7.
Ver. 1.0
Delete node 80
2.
root
. .
24 36
52
.
3.
.
59
68
.
parent
4.
.
70
72
.
currentNode 5.
.
75 child
80
6.
7.
Ver. 1.0
Delete node 80
2.
root
. .
24 36
52
.
3.
.
59
68
.
parent
4.
.
70
72
.
currentNode 5.
.
75 child
80
6.
7.
Ver. 1.0
Delete node 80
2.
root
. .
24 36
52
.
3.
.
59
68
.
parent
4.
.
70
72
.
currentNode 5.
.
75 child
80
6.
7.
Ver. 1.0
Delete node 80
2.
root
. .
24 36
52
.
3.
.
59
68
.
parent
4.
.
70
72
.
currentNode 5.
.
75 child
80
6.
7.
Ver. 1.0
Delete node 80
2.
root
. .
24 36
52
.
3.
.
59
68
.
parent
4.
.
70
72
.
currentNode 5.
.
75 child
80
6.
7.
Ver. 1.0
Delete node 80
2.
root
. .
24 36
52
.
3.
.
59
68
.
parent
4.
.
70
72
.
currentNode 5.
.
75 child
80
6.
7.
Ver. 1.0
Delete node 80
2.
root
. .
24 36
52
.
3.
.
59
68
.
parent
4.
.
70
72
.
currentNode 5.
.
75
80
6.
7.
Write an algorithm to delete a node, which has two children from a binary search tree.
Ver. 1.0
Session 13
2.
. .
24 36
52
. .
68
.
3.
59
.
70
72
. .
80
4.
5.
75
Ver. 1.0
Session 13
Delete node 72
2.
root
. .
24 36
52
.
parent
.
59
68
.
currentNode
3.
.
70
72
. .
80
4.
5.
75
Ver. 1.0
Session 13
Delete node 72
2.
root
. .
24 36
52
.
parent
.
59
68
.
currentNode
3.
.
70
72
. .
80
4.
5.
75
Ver. 1.0
Session 13
Delete node 72
2.
root
. .
24 36
52
.
parent
.
59
68
.
currentNode
3.
.
70
72
. .
80
4.
5.
Inorder_suc 75
Ver. 1.0
Session 13
Delete node 72
2.
root
. .
24 36
52
.
parent
.
59
68
.
currentNode
3.
.
70
72
. .
80
4.
5.
Inorder_suc
75
Ver. 1.0
Session 13
Delete node 72
2.
root
. .
24 36
52
.
parent
.
59
68
.
currentNode
3.
.
70
72
. .
80
4.
5.
Inorder_suc
75
Inorder_suc
Ver. 1.0
Session 13
Delete node 72
2.
root
. .
24 36
52
.
parent
.
59
68
.
currentNode
3.
.
70
72 75
. .
80
4.
5.
75
Inorder_suc
Ver. 1.0
Session 13
Delete node 72
2.
root
. .
24 36
52
.
parent
.
59
68
.
currentNode
3.
.
70
75
. .
80
4.
5.
75
Inorder_suc
Ver. 1.0
Session 13
root
. .
24 36
52
.
parent
.
59
68
.
currentNode
3.
.
70
75
. .
80
4.
5.
75
Session 13
Problem Statement:
Write a program to implement insert and traverse operations on a binary search tree that contains the words in a dictionary.
Ver. 1.0
Session 13
Ver. 1.0
Session 13
Inserting a node in a binary search tree requires you to first locate the appropriate position for the node to be inserted. You need to check for the following three cases before deleting a node from a binary search tree.
If the node to be deleted is the leaf node If the node to be deleted has one child (left or right) If the node to be deleted has two children
Ver. 1.0
Session 13