Change of Key in BST
Submissions: 1783   Accuracy:

34.23%

  Difficulty: Easy   Marks: 2
Associated Course(s):   Sudo Placement 2019

Given a Binary Search Tree of size N, your task is to complete the function changeKey() that change old key value present in the tree and changes it to new key value.
Example:

Input: Root of below tree
              50
           /     \
          30      70
         /  \    /  \
       20   40  60   80 
     Old key value:  40
     New key value:  10

Output: BST should be modified to following
              50
           /     \
          30      70
         /       /  \
       20      60   80  
       /
     10


Input:
The function takes three arguments, reference pointer to the root node of the BST, old key value of the node and a new key value.
There will be T test cases and for each test case the function will be called separately.

Output:
For each test case output the Inorder traversal of the Tree.

Constraints:
1<=T<=100
1<=N<=500

Example:
Input:

1
7
20 8 22 4 12 10 14
8 1
Output:
1 4 10 12 14 20 22


Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code.

** For More Input/Output Examples Use 'Expected Output' option **

Author: harshitsidhwa


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.