1 / 21

On RAM PRIORITY QUEUES

On RAM PRIORITY QUEUES. MIKKEL THORUP. 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. Abstract.

lynsey
Télécharger la présentation

On RAM PRIORITY QUEUES

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 A: B: .02 / 1 .59 0 .11 / .32 2 1 n: 10 .52 3 2 .32 / 4 .02 3 BUCKET SORT(A) 5 .11 .45 / 4 1. n ← length[A] 6 .45 5 .59 .52 / .59 / 2. fori ← 1 ton … 3. do insert A[i] into list 10 .90 4. fori ← 1 to n-1 9 .90 / 5. do sort list B[i] with INSERTION SORT 6. concatenate the lists B[0], B[1], …, B[n-1] together in order

  9. Bucket Sort Time Complexity: Let ni 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 length(b) <= ω/k

  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. 1 2 5 6 3 4 7 8 O(logk) 3 7 11 15 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)isthe 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 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 0 1 2 … i x length = i +1

  18. Preliminaries memory x 0 1 2 … i … n-2 n-1 x =

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

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

More Related