290 likes | 515 Views
CS3223 Tutorial 3. Fan Qi fan.qi@nus.edu.sg Database Lab 1, com1 #01-08. Linear Hash. Parameters: Level: indicates the rounds of splitting Initial hash size: buckets Next: next buckets to be split Notations: Bucket : Hash size at beginning of round :
E N D
CS3223 Tutorial 3 Fan Qi fan.qi@nus.edu.sg Database Lab 1, com1 #01-08
Linear Hash • Parameters: • Level: indicates the rounds of splitting • Initial hash size: buckets • Next: next buckets to be split • Notations: • Bucket : • Hash size at beginning of round : • Hash function in round : • Properties: • Split Image of :
Linear Hash • Basic operations: • GetBucketNumber() • SplitBucket() • GetBucketNumber(k) • 1. Check the range of • 2. Use if • SplitBucket(): • 1. Split and Redistribution • 2. Increment next • 3. Rewind next if necessary
Sorting Why 2 N ? • External Sorting: • A variant of Merge Sort • B-1 way Merge Sort: CPU Cost? Memory Input 1 Input 1 Input 1 Input 1 Input 1 Input 1 Input 1 Input 1 Output Input 1 Input 1 Input 1 Input 1
Question 1: 3,5,7,11,17, 19,23,0,4,29,33,13,6 GetBucket -> Check Split -> Increment next -> Rewind next
Question 1: 3,5,7,11,17, 19,23,0,4,29,33,13,6 Split & Redistribute GetBucket -> Check Split -> Increment next -> Rewind next
Question 1: 3,5,7,11,17, 19,23,0,4,29,33,13,6 Split & Redistribute GetBucket -> Check Split -> Increment next -> Rewind next
Question 1: 3,5,7,11,17, 19,23,0,4,29,33,13,6 GetBucket -> Check Split -> Increment next -> Rewind next
Question 1: 3,5,7,11,17, 19,23,0,4,29,33,13,6 Split & Redistribute GetBucket -> Check Split -> Increment next -> Rewind next
Question 1: 3,5,7,11,17, 19,23,0,4,29,33,13,6 GetBucket -> Check Split -> Increment next -> Rewind next
Question 1: 3,5,7,11,17, 19,23,0,4,29,33,13,6 Split & Redistribute GetBucket -> Check Split -> Increment next -> Rewind next
Question 1: 3,5,7,11,17, 19,23,0,4,29,33,13,6 GetBucket -> Check Split -> Increment next -> Rewind next
Question 1: 3,5,7,11,17, 19,23,0,4,29,33,13,6 GetBucket -> Check Split -> Increment next -> Rewind next
Question 2: Insert 15
Question 2: Insert 15
Question 2: Delete 44 36
Question 2: 100 is removed
Question 2: Minimum Entry to achieve 2 overflow pages in 1 bucket
Question 2: Minimum Entry to achieve 2 overflow pages in 1 bucket Keep Filling Up Page 11 -> 63, 127,255, 511,1023
Question 2: Minimum Entry to achieve 2 overflow pages in 1 bucket
Question 3: Minimum insertions to cause all bucket split once ?
Question 3: Hint: create collisions after split Insert any element in 11to split 00 : 63 ( 00001111)
Question 3: Hint: Trying to create collision after split Insert any two elements in 01 to split 01 : 67( 00111001), 131(0111001)
Question 3: Hint: Trying to create collision after split Insert any element in 001 to split 10: 41 (00101001)
Question 3: Hint: Trying to create collision after split Insert any 4 elements in 000 to split 11: 0, 8, 16, 32
Question 3: Hint: Trying to create collision after split 63, 67,131, 41, 0, 8, 16,32
Question 4 (d): • Pass 0: runs are produced. • Pass 1: Merge all runs therefore, • Take the integer of B
Self-Thinking • How to write a program to do a K-way merge? • Let k = 4 • Take 4 sorted array, merge them into one sorted array • Any data structure to use?
Thank you! See you next week!