Google

www.google.com
Employer Engaged

Interview Question

Software Developer Interview

Given a node in a binary tree find the next greatest value

  in the entire node.
Answer

Interview Answer

2 Answers

0

I guess it is a binary search tree? And does each node have a parent pointer?

Anonymous on Feb 24, 2012
0

for BST : get the node and find the inorder successor
if(n->right) : find minimum in n->right
else
find parent of n in loop, till n is parent->right :
(n = parent, find parent(n)

aranjany on Mar 5, 2012

Add Answers or Comments

To comment on this, Sign In or Sign Up.