write a program in java to find the successor and the predecessor of a number
Answers
Answered by
1
Answer:
Input: root node, key
output: predecessor node, successor node
1. If root is NULL
then return
2. if key is found then
a. If its left subtree is not null
Then predecessor will be the right most
child of left subtree or left child itself.
b. If its right subtree is not null
The successor will be the left most child
of right subtree or right child itself.
return
3. If key is smaller then root node
set the successor as root
search recursively into left subtree
else
set the predecessor as root
search recursively into right subtree
Similar questions
English,
10 days ago
Hindi,
20 days ago
Psychology,
9 months ago
English,
9 months ago
Math,
9 months ago