ZigZag and ZigZig in a splay tree?

believe my tree looks like this

                 5
                / \
               3   7
              / \ / \
             2  4 6  8

in that, when searching for an element 2, the zigzig operation is performed in time, so first we rotate parent and ancestor of 2, then rotate a parent and 2.

in the same case, consider what we are looking for 4, that the zigzag time operation will be performed. first we rotate 4 and its parent, then it 4 and its ancestorwill be rotated.

why we did it, in a zigzag, why we don’t rotate parent and ancestorinstead searching node and parent.

Please explain me?? Thanks in advance.

+4
source share
1 answer

. , , O(lg n) , m . splay(x) node x , , x , , x, x. , x , , .

- . . , , , , : splay O(m lg n), m .

+1

Source: https://habr.com/ru/post/1569696/


All Articles