Goldman Sachs Interview Question
637 Interview Reviews |
Back to all Goldman Sachs Interview Questions & Reviews
Interview questions and reviews posted anonymously by interview candidates
Interview Question for Senior Software Engineer at Goldman Sachs:
Write an algorithm to rotate a node of a binary tree.
| Tags: | algorithm See more , See less 8 |
See more for this Goldman Sachs Senior Software Engineer Interview
Helpful Question?
Yes |
No
Inappropriate?



0 of 0 people found this helpful
by avi:
Node r = p.right;
p.right = r.left;
if (r.left != null)
r.left.parent = p;
r.parent = p.parent;
if (p.parent == null)
root = r;
else if (p.parent.left == p)
p.parent.left = r;
else
p.parent.right = r;
r.left = p;
p.parent = r;
}
void rotateRight(Node p) {
Node l = p.left;
p.left = l.right;
if (l.right != null) l.right.parent = p;
l.parent = p.parent;
if (p.parent == null)
root = l;
else if (p.parent.right == p)
p.parent.right = l;
else p.parent.left = l;
l.right = p;
p.parent = l;
}