Cheatography
https://cheatography.com
Cheatsheet for my data structures final exam
This is a draft cheat sheet. It is a work in progress and is not finished yet.
Splay Trees
Top Down Splay: |
function Splay(node x, root r): if x == null or r == null: return r while x is not the root: if x is a child of the root: # Zig case if x is the left child: perform right rotation on the root else: perform left rotation on the root else: parent = parent(x) grandparent = parent(parent(x)) if x and parent are both left children (or both right children): # Zig-Zig case if x is a left child: perform right rotation on grandparent perform right rotation on parent else: perform left rotation on grandparent perform left rotation on parent else: # Zig-Zag case if x is a left child: perform right rotation on parent perform left rotation on grandparent else: perform left rotation on parent perform right rotation on grandparent return x # x is now the root |
Splay Trees
Top Down Splay: |
function Splay(node x, root r): if x == null or r == null: return r while x is not the root: if x is a child of the root: # Zig case if x is the left child: perform right rotation on the root else: perform left rotation on the root else: parent = parent(x) grandparent = parent(parent(x)) if x and parent are both left children (or both right children): # Zig-Zig case if x is a left child: perform right rotation on grandparent perform right rotation on parent else: perform left rotation on grandparent perform left rotation on parent else: # Zig-Zag case if x is a left child: perform right rotation on parent perform left rotation on grandparent else: perform left rotation on parent perform right rotation on grandparent return x # x is now the root |
|
|
|
|
|