Download presentation
Presentation is loading. Please wait.
Published byMagdalene Lyons Modified over 9 years ago
1
Cache-Oblivious Dynamic Dictionaries with Update/Query Tradeoff Gerth Stølting Brodal Erik D. Demaine Jeremy T. Fineman John Iacono Stefan Langerman J. Ian Munro Result presented at SODA 2010
2
Dynamic Dictionary Search(k) Insert(e) Delete(k)
3
I/O Model [Aggarwal, Vitter 88] CPU Fast Memory block M/BM/B B Slow Memory B Cost: the number of block transfers (I/Os)
4
Cache-Oblivious Algorithms [Frigo, Leiserson, Prokop, Ramachandran 99] Algorithms not parameterized by M or B Analyze in ideal-cache model — I/O model, except optimal replacement policy is assumed CPU Fast Memory block M/BM/B B Slow Memory B
5
Cache-Oblivious Dynamic Dictionaries Cache-AwareSearchInsert B-tree [BM72] O(log B N) Buffered B-tree [BF03] O((1/ )log B N)O((1/ B 1- )log B N)* Cache-ObliviousSearchInsert CO B-tree [BDF-00, BDIW04,BFJ02] O(log B N)O(log B N + …) COLA [BFF-CFKN07] O(log 2 N)O((1/B)log 2 N)* Shuttle Tree [BFF-CFKN07] O(log B N) O((1/B Ω(1/(log log B) 2 ) )log B N + …)* xDict [this paper] O((1/ )log B N)O((1/ B 1- )log B N)* † * amortized † assumes M = Ω(B 2 )
6
Building an xDict ( = 1/2) lglgN x-boxes of squaring capacities Insert: insert into smallest box When a box reaches capacity, Flush it and Batch- Insert into the next box O((1/√B) log B x) cost is dominated by largest box O((1/√B) log B N) Search: search in each x-box O(log B x) cost is dominated by largest box O(log B N) 2 2 1 -box 2 2 2 -box 2 2 lglgN -box …
7
x-Box = dictionary with capacity x 2 Batch-Insert(D,A): insert Θ (x) presorted objects — cost O((1/√B)log B x) per element Search(D, κ ): — cost is O(log B x) Flush(D): produce a size-x 2 sorted array A containing all the elements in the x-box D — cost is O(1/B) per element
8
size-x input buffer Recursive x-Box size-x 2 output buffer size-x 3/2 middle buffer √x-box Upper level: at most x 1/2 /4 subboxes Lower level: at most x/4 subboxes input middle …… output subboxes stored contiguously in arbitrary order Unused (currently empty) subboxes are preallocated … …
9
size-x input buffer x-Box Space Usage size-x 2 output buffer size-x 3/2 middle buffer √x-box Upper level: at most x 1/2 /4 subboxes Lower level: at most x/4 subboxes … … Theorem: An x-Box uses at most cx 2 space (within constant factor of capacity/output buffer)
10
Fractional Cascading within x-Box size-x input buffer size-x 2 output buffer size-x 3/2 middle buffer √x-box Upper level: at most x 1/2 /4 subboxes Lower level: at most x/4 subboxes Propagate samples upwards + Lookahead pointers
11
Searching in an x-Box Describe searches by the recurrence S(x) = 2S(√x) + O(1) with base case S(<√B) = 0 Solves to O(log B N) √x-box Upper level: at most x 1/2 /4 subboxes Lower level: at most x/4 subboxes size-x input buffer size-x 3/2 middle buffer size-x 2 output buffer
12
Flush Moves all real elements to the output buffer in sorted order. size-x 2 output buffer √x-box Upper level: at most x 1/2 /4 subboxes Lookahead pointers are rebuilt to facilitate searches. Most subboxes remain empty. size-x input buffer size-x 3/2 middle buffer Lower level: at most x/4 subboxes
13
Batch-Insert 1.Merge sorted input into input buffer. + input buffer middle buffer output buffer
14
Batch-Insert 1.Merge sorted input into input buffer. 2.If input buffer is “full enough,” Batch-Insert into upper-level subboxes (in chunks of Θ (√x)) middle buffer output buffer
15
Batch-Insert 1.Merge sorted input into input buffer. 2.If input buffer is “full enough,” Batch-Insert into upper-level subboxes (in chunks of Θ (√x)) 3.Whenever a subbox is near capacity, Flush it, then split it into two subboxes input buffer middle buffer output buffer
16
Batch-Insert 1.Merge sorted input into input buffer. 2.If input buffer is “full enough,” Batch-Insert into upper-level subboxes (in chunks of Θ (√x)) 3.Whenever a subbox is near capacity, Flush it, then split it into two subboxes 4.If no empty subboxes remain, Flush all of them and merge output buffers into middle buffer. input buffer middle buffer output buffer
17
Batch-Insert Analysis The following recurrence describes the cost, per element I(x) = O(x/B)/x + O(√x)/x + 2I(√x) + F(x) + … Upper level: at most x 1/2 /4 subboxes Merging into input buffer Insert recursively into upper and lower levels Random accesses to each upper-level subbox Flush & split the box size-x input size-x 3/2 middle size-x 2 output buffer
18
O(√x) Random Accesses is Cheap Rely on tall-cache assumption M ≥ B 2 Case 1. x 3/2 ≥ B 3/2. Then √x ≥ √B, and hence we have O(1/√x) = O(1/√B) Case 2. x 3/2 < B 3/2 ≤ M. Pay to load entire upper level into memory, costing O(x 3/2 /B)/x = O(√x/B) = O(1/√B). All other random accesses are free. input middle …… output upper-level subboxes stored contiguously in arbitrary order O(x 3/2 ) space
19
Batch-Insert Analysis I(x) = O(x/B)/x + O(√x)/x + 2I(√x) + F(x) + … = O(1/√B) + 2I(√x) I(<√B)= 0 Upper level: at most x 1/2 /4 subboxes Solves to I(x) = O((1/√B) log B N).
20
Generalizing to O((1/ ε B 1- ε )log B N) Parameterize by 0 < α ≤ 1, where α = ε /(1- ε ) size-x input buffer size-x 1+ α output buffer size-x 1+ α/2 middle buffer √x-box Upper level: at most x 1/2 /4 subboxes Lower level: at most x 1/2+ α /2 /4 subboxes 2 (1+ α) 1 2 (1+ α) 2 -box 2 (1+ α) i -box 1/ ε overhead comes from geometric sum in xDict
21
Results Summary Cache-AwareSearchInsert B-tree [BM72] O(log B N) Buffered B-tree [BF03] O((1/ )log B N)O((1/ B 1- )log B N)* Cache-ObliviousSearchInsert CO B-tree [BDF-00, BDIW04,BFJ02] O(log B N)O(log B N + …) COLA [BFF-CFKN07] O(log 2 N)O((1/B)log 2 N)* Shuttle Tree [BFF-CFKN07] O(log B N) O((1/B Ω(1/(log log B) 2 ) )log B N + …)* xDict [this paper] O((1/ )log B N)O((1/ B 1- )log B N)* † * amortized † assumes M = Ω(B 2 )
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.