splay trees Flashcards
splay tree property
Data more recently accessed is near the root
The operation on each element will rearrange the tree so that this element will be placed at the root of the tree
zig
right rotation
zag
left rotation
zig-zig
right-right rotate
zag-zag
left-left rotate
zig-zag
right left rotate
zag-zig
left right rotate
Splay Operations: Find
Find the node in normal BST manner
Splay the node to the root
what is amortized analysis?
In Amortized Analysis, we analyze a sequence of operations and guarantee a worst-case average time which is lower than the worst-case time of a particular expensive operation.
splay tree algorithm analysis
Worst case time is π(π)
Amortized time for all operations is π(logβ‘π)
a sequence of π operations on an π-node splay tree takes π(π logβ‘π) time.
Maybe not now, but soon, and for the rest of the operations
what is the final depth of a node on the splay path?
If a node on the access path is at depth π before the splay, itβs final depth β€3+πβ2
splay tree insert and delete
Insert x
Insert x as normal then splay x to root.
Delete x
Find x
Splay x to root and remove it
Splay the max in the left subtree to the root
Attach the right subtree to the new root of the left subtree.
π(π2) time for π inserts