consider my tree is like this
5
/ \
3 7
/ \ / \
2 4 6 8
in that, when we search a element 2
that time zigzig operation will be performed, so first
we rotate the parent and ancestor of 2
, then we rotate a parent and 2
.
in the same case , consider we are searching 4
, that time zigzag operation will be performed. in that first we rotate the 4 and its parent
then 4 and its ancestor
will be rotated.
why we did like that, in zigzag, why we are not rotate the parent and ancestor
instead of searching node and parent
.
Please explain me?? Thanks In Advance.