In BST, if each node does not have a pointer to its parent, instead, have a pointer to its successor (also has left and right child pointer). How could we design an algorithm to get its parent based on the successor pointer?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
For a node
n, we can repeatedly get the successorsuntil we get one thats.left == n.sis then the parent. If no such node is found,nis a right child and we repeatedly get the successors, starting from the first element (easy to get by repeatedly callinge = e.left) until we gets.right == n, thensis the parent.