计算几何 W38 I/O Model and Permutation Lower Bound
课前预习
Random Access Machine Model
standard theoretical model of computation
- infinite memory
- uniform access cost
simple model crucial for success of computer industry
Hierarchical Memory
modern machines have complicated memory hierarchy
- levels get larger and slower further away from CPU
- data moved between levels using large blocks
many issues influence performance
- cache misses, TLB misses, branch mis-predictions etc.
Disk access is slower than main memory access
important to store/access data to take advantage of blocks
Scalability problems
most programs developed in RAM-model
- run on large dataset because OS moves blocks as needed
modern OS utilize sophisticated paging and pre-fetching strategies
- but if program makes scattered accesses even good OS can’t take advantage of block access
I/O Model
num of items in the problem instance
num of items per disk block
num of items that fit in main memory
num of items in output
I/O: move block between memory and disk
assume that
Fundamental bounds
internal | external | |
---|---|---|
scanning | ||
sorting | ||
permuting | ||
searching |
Note:
- Linear I/O
- Permuting not linear
- Permuting and sorting bounds are equal in all practical cases
- cannot sort optimally with search tree
Large difference between and !!!
Queue and Stacks
queue
- maintain push and pop blocks in main memory
stack
- maintain push and pop block in main memory
Sorting
- sorted lists and be merged in I/O
- unsorted list can be distributed using split elements in I/O
Merge sort
- create memory sized sorted lists
- repeatedly merge lists together at a time
Multi-way quick-sort
- compute splitting elements
- distribute unsorted list into unsorted lists of equal size
- recursively split lists until fit in memory
Computing splitting elements
in internal memory: linear time selection
selection algorithm: finding i-th element in sorted order
- select median of every group of 5 elements
- recursively select median of selected elements
- distribute elements into 2 lists using computed median
- recursively select in one of two lists.
analysis
- step 1 and 3 performed in I/O
- step 4 recursion on at most
I/O
后面的分析一点也看不懂,头大……
课堂笔记
Intro and Motivation
2 trends:
- Parallelism
- Non-Uniform Memory Access, caches…
start with 2 level of memory
I/O Model
- slow but large mem
- fast but limited mem of size
- block transfer of elements at a time
block transfer is a common architectural phenomenon
I/O algorithms borrowed from PRAM
I/O Model
aka external memory model
input size:
memory size:
blocked storage, block size:
fixed cost to read/write one block
almost the same as pre-learning…
…
Searching
store N items (values)
search for a key (value)
ordinary:
search
report values in an interval
static, blocking:
- search
- report values in an interval
Dynamic Search Tree
like Splay tree.
rotation destroys blocking!
B-Tree
(a,b)-tree (a>=2, b>=2*a-1)
- completely balanced
- leaves store between a and b values
- except root, degrees between a and b
- root degree between 2 and b
- ordered like a search tree
insertion
- search and insert in a leaf v
- if v not overflowing done!
- else split v
split
- split v into two
- add a key to parent of v
- recurse into parent of v
deletion
- search and delete from a leaf v
- if v not underflowing done!
- else re-balance b
Buffer Trees
idea: to be lazy