Not able to unserstand

Not able to understand

Hello @shivansh.sm1,

Hopefully, the following points will help you to better understand the logic:

  1. In BST(i.e. Binary Search Tree), each node can have two subtrees i.e. left and right.
  2. All elements of left subtree are smaller than the element present at that node.
  3. All elements of right subtree are greater than the element present at that node.
  4. To flattern a BST, you should know the nodes in the both the subtrees which has the smallest and largest values.
  5. You will connect the right pointer of lagest valued node in left subtree with the current node.
  6. Similarly, the right of current node to the smallest valued node in right subtree.
  7. For current node after flattering, the smallest element will be the smallest of left subtree and lasrgest will be the largest of right subtree.

NOTES:

  1. You have to follow bottom up approach (from leaf node to upwards in the tree hierarchy)
  2. You have to return the pair smallest and largest values node from each function call.
  3. You have to deal with 4 types of nodes.
    2.1. leaf node (no subtrees): both smallest and largest elements are the leaf node itself.
    2.2. node with no right subtree: smallest is smallest of left subtree and lagest is the current node itself.
    2.3. node with no left subtree: smallest is the current node itself and largest is the largest of the right subtree.
    2.4. both subtrees are present: point 5,6,7

Give a like if you are satisfied.

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.