Why we are replacing by max of left subtree

in case 4, when neither node.left and right are null, why are we replacing the node by max of left subtree, we can also replace it by the min of right subtree, why are we not considering that case

you are right. you can also replace it by min of right subtree.
so when a node to be deleted has both child, that node can be replaced either by its inorder predecessor or inorder successor.

  1. inorder successor: the node next to this node in inorder traversal of tree. it is min of right subtree if right subtree exists.
  2. inorder predecessor: the node previous to this node in inorder traversal of tree. it is max of left subtree if left subtree exists.

these are actually 2 ways of doing it. you can follow only 1 way.
these are not 2 cases that we separately need to consider in deletion. just choose one way out of these 2 ways.

thanks

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.