Presentation on theme: "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,"— Presentation transcript:
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 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
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
RAM model Random Access Machine (RAM) A CPU An potentially unbounded bank of memory cells, each of which can hold arbitrary number of character
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.
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.
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, B, …, B[n-1] together in order.59.32.52.02.11.45 … A: 1 2 3 4 5 6 10 B:.90 0 1 2 3 4 5 9.02/.11/.32/.59/ /.45/.90/.52 10 n:
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.
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.
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) <=
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. 12563478 371115 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).
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)
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
Range Reduction Time Complexity: We apply the range reduction times, at a total cost O(nloglogn)
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.
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
Your consent to our cookies if you continue to use this website.