Download presentation

Presentation is loading. Please wait.

Published byConnor Jipson Modified about 1 year ago

1
On RAM PRIORITY QUEUES MIKKEL THORUP

2
Objective Sorting is a basic technique for a lot of algorithms. e.g. find the minimum edge of the graph, scheduling, …. We want to decrease the time of sorting, and the author presented a new data structure to implement sorting.

3
Abstract First Result: Implement a queue supporting find-min in constant time, delete-min in O(nloglogn) Speedup Dijkstra’s Algorithm with this queue Second Result: Sorting is equivalent to priority queue

4
Machine Model A model of computation is a simplied abstraction of a computer that runs a program. The running time of an algorithm in the model is the number of elementary steps needed to complete an implementation of the algorithm. Turing Machine Comparison Model Random Access Machine

5
RAM model Random Access Machine (RAM) A CPU An potentially unbounded bank of memory cells, each of which can hold arbitrary number of character

6
The RAM Model Each “simple” operation (+, -, =, if, call procedure) takes exactly 1 step. Basically, any basic operation that takes a small, fixed amount of time we assume to take just one step. We measure the run time of an algorithm by counting the number of steps it takes. We allow ourselves to use keys and segments of keys as addresses.

7
Bucket Sort Bucket-sort sorts in linear time on the average with some assumptions. Assumption: Input elements are evenly distributed over the interval [0,1). Data structures used: Input: A[1…n] where Auxiliary: B[0…n-1] is a set of buckets (implemented as linked list). Each of B[i] is a pointer to a sorted listed of A[j]’s that fall into bucket i.

8
Bucket Sort BUCKET SORT(A) 1. n ← length[A] 2. for i ← 1 to n 3. do insert A[i] into list 4. for i ← 1 to n-1 5. do sort list B[i] with INSERTION SORT 6. concatenate the lists B[0], B[1], …, B[n-1] together in order … A: B: /.11/.32/.59/ /.45/.90/ n:

9
Bucket Sort Time Complexity: Let n i be the random variable denoting number of elements placed inn bucket B[i]. Since insertion sort runs in quadratic time, the expected time to sort bucket B[i] is. The probability of the element falling in bucket B[i] is p = 1/n.

10
Sorting in O(nloglogn) time Use “packed sort” and “range reduction” to achieve the goal. We will introduce “packed sort” and “range reduction” in next slides.

11
Packed Sort Idea: Packed sorting saves on integer sorting by packing several integers into a single word and operating simultaneously on all of them at unit cost. It stores keys in the so-called word representation, i.e., k to a word, where k = Θ(lognloglogn). one word our integer ω ω/kω/k length(b) <=

12
Packed Sort There is a subroutine to merge two sorted sequences, each consisting of k keys and given in the word representation, in O(logk) time O(logk) It can handle k keys at a cost of O(logk), it saves a factor of Θ(k/logk) relative to standard merge sort, so that the total time needed comes to O(nlogn logk/k) = O(n).

13
Packed Sort Don’t Care! T(n,b) is the worst-case time needed to sort n integers of b bits each. T(n,b) = O(n)

14
Range Reduction Idea: In O(n) time we can reduce by about half the number bits in the integers to be sorted. … slice origin integer to small pieces … do Packed Sort

15
Range Reduction Time Complexity: We apply the range reduction times, at a total cost O(nloglogn)

16
Fast Basic Priority Queue The goal is to create a priority queue supporting find-min in constant time and insert and delete-min in O(loglogn) time, where n is the current number of keys in the queue. We implement priority queue with short keys first. There is a priority queue with capacity for n ( ω /lognloglogn ) bit keys, supporting insert, find-min, and delete-min on integers in constant time per operation.

17
Preliminaries n : the number of the input keys ω : the bits of the address of memory x[i] : the (i+1) th bit from the left 01…i2 length = i +1 x

18
Preliminaries i201……n-2n-1 memory x x =

19
Preliminaries x x[i]x[i] length = i length = ω -(j-i+1) ω

20
Preliminaries flip bit i 1 x[i]x[i] ω ω -i-1 0…0 1<< (ω-1- i ) ⊕ x[i] ⊕ expo(x) 1 0…0 ω- expo(x) -1

21

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google