Professional Documents
Culture Documents
Lect 11
Lect 11
Lect 11
10 If youre forced to make a really deep access: 17 Since youre down there anyway, fix up a lot of deep nodes!
5 2 3 9
Splay: Zig-Zag*
g g
Splay: Zig-Zig*
k
p p
k
W Z p g p X
W Y Z W X
Y
*Just
like an
root
?
3 3 4 6 5 5 6
5
Find(6)
Relative depth of p, Y, Z?
Why not drop zig-zig and just zig all the way? 4
6
Still Splaying 6
1 2 1 6 1 6
Finally
6 1
?
3 6 5 4 2 4
7
?
3 5 2 4 3 5 2 4
8
3 5
?
3 Find(4) 2 4 5 2
9
?
4 3 5 2
10
4 3
Original Tree
1
But Wait
What happened here?
2 3 4 5 6
1 3 2 5
Didnt two find operations take linear time instead of logarithmic? What about the amortized O(log n) guarantee?
11
12
Overall, nodes which are low on the access path tend to move closer to the root
13
14
15
16
Join
given two trees such that (stuff in L) < (stuff in R), merge them: splay L R
max
Now what?
17 18
Delete(4) 6 1 4 2 7 9
Delete Example
4 find(4) 1 2 7 2 1 6 9 7 7 1 6 9 1 2 Find max 2 6 9
19
One of the assumptions that Big-Oh makes is that all operations take the same amount of time. Is that really true?
22
Definitions
Cycle (for our purposes) the time it takes to execute a single simple instruction. (ex. Add 2 registers together) Memory Latency time it takes to access memory
SRAM 8KB - 4MB
Cache
Cache 2-10 ns
Disk many GB
23
Disk
Moores Law
Memory wall
100
10
1 89 91 93 95 97 99 01
25
26
Locality
Temporal Locality (locality in time) If an item is referenced, it will tend to be referenced again soon.
Spatial Locality (locality in space) If an item is referenced, items whose addresses are close by will tend to be referenced soon.
27
28
Caches
Each level is a sub-set of the level below. Cache Hit address requested is in cache Cache Miss address requested is NOT in cache Cache line size (chunk size) the number of contiguous bytes that are moved into the cache at one time
29
Examples
x = a + 6; y = a + 5; z = 8 * a; x = a[0] + 6; y = a[1] + 5; z = 8 * a[2];
30