BST Deletion failing test case

8 10 1 6 7 8 9 10 13 14 -1
Deletion element: 10
This test case gives the wrong answer in the code taught in the BST Deletion video, as 9 should be replaced with the replacing element but 13 is replaced which is not the minimum in the right subtree.
Here is the code https://ide.codingblocks.com/s/23088

Hello @mohitsethia,

The test case is itself ambiguous because it contains two nodes with value 10.
and you want to delete that node only.

BTW, the code is working fine.
Reason:
As per a condition in the insertInBST() function:
if(data<=root->data){
root->left = insertInBST(root->left,data);
}
8 will be the root and 9 will be the leftmost node of the right subtree and the first 10 will be right child of 9 and the second 10 will be the leaf node and the left child of the first 10.

So, after deleting 10. i.e. the first 10, the second 10 being the only child of the deleted node will take its position.
The same is shown in the output as well:
8,
1,13,
6,9,14,
7,10,
8,

Hope, this would help.

Oh Okay, I understood now, we replace the element with the minimum of the right sub-subtree or the maximum of the left sub-subtree, I was taking the minimum of the whole subtree with root 8.
8
/ \
1 10
\ /
6 9 13
\ \
7 10 14

Yes @mohitsethia,

Please, mark it as resolved if you have no more doubts related this problem.:slightly_smiling_face:

how to mark as resolved? Where is the option?

Hey @mohitsethia,

You might get an option in the doubt preview.