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,

Slides:



Advertisements
Similar presentations
Algorithms (and Datastructures) Lecture 3 MAS 714 part 2 Hartmut Klauck.
Advertisements

Theory of Computing Lecture 3 MAS 714 Hartmut Klauck.
1 More Sorting; Searching Dan Barrish-Flood. 2 Bucket Sort Put keys into n buckets, then sort each bucket, then concatenate. If keys are uniformly distributed.
Analysis of Algorithms CS 477/677 Linear Sorting Instructor: George Bebis ( Chapter 8 )
Sorting in Linear Time Comp 550, Spring Linear-time Sorting Depends on a key assumption: numbers to be sorted are integers in {0, 1, 2, …, k}. Input:
Linear Sorts Counting sort Bucket sort Radix sort.
CSE 3101: Introduction to the Design and Analysis of Algorithms
MS 101: Algorithms Instructor Neelima Gupta
1 Sorting in Linear Time How can we do better?  CountingSort  RadixSort  BucketSort.
Sorting in linear time Comparison sort: –Lower bound:  (nlgn). Non comparison sort: –Bucket sort, counting sort, radix sort –They are possible in linear.
Mudasser Naseer 1 5/1/2015 CSC 201: Design and Analysis of Algorithms Lecture # 9 Linear-Time Sorting Continued.
Counting Sort Non-comparison sort. Precondition: n numbers in the range 1..k. Key ideas: For each x count the number C(x) of elements ≤ x Insert x at output.
Lower bound for sorting, radix sort COMP171 Fall 2005.
CSCE 3110 Data Structures & Algorithm Analysis
CSE332: Data Abstractions Lecture 12: Introduction to Sorting Tyler Robison Summer
Comp 122, Spring 2004 Keys into Buckets: Lower bounds, Linear-time sort, & Hashing.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu.
Comp 122, Spring 2004 Lower Bounds & Sorting in Linear Time.
CS421 - Course Information Website Syllabus Schedule The Book:
Tirgul 4 Sorting: – Quicksort – Average vs. Randomized – Bucket Sort Heaps – Overview – Heapify – Build-Heap.
Tirgul 8 Universal Hashing Remarks on Programming Exercise 1 Solution to question 2 in theoretical homework 2.
CSE 326: Data Structures Sorting Ben Lerner Summer 2007.
Tirgul 4 Order Statistics Heaps minimum/maximum Selection Overview
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 5 Linear-time sorting Can we do better than comparison sorting? Linear-time sorting.
1 ES 314 Advanced Programming Lec 2 Sept 3 Goals: Complete the discussion of problem Review of C++ Object-oriented design Arrays and pointers.
Lower Bounds for Comparison-Based Sorting Algorithms (Ch. 8)
Computer Algorithms Lecture 11 Sorting in Linear Time Ch. 8
Sorting in Linear Time Lower bound for comparison-based sorting
CSE 373 Data Structures Lecture 15
Lecture 2 Computational Complexity
Unit III : Introduction To Data Structures and Analysis Of Algorithm 10/8/ Objective : 1.To understand primitive storage structures and types 2.To.
1 Sorting in O(N) time CS302 Data Structures Section 10.4.
Jessie Zhao Course page: 1.
Lecture 4. RAM Model, Space and Time Complexity
David Luebke 1 10/13/2015 CS 332: Algorithms Linear-Time Sorting Algorithms.
CSC 41/513: Intro to Algorithms Linear-Time Sorting Algorithms.
Analysis of Algorithms CS 477/677
Fall 2015 Lecture 4: Sorting in linear time
Mudasser Naseer 1 11/5/2015 CSC 201: Design and Analysis of Algorithms Lecture # 8 Some Examples of Recursion Linear-Time Sorting Algorithms.
Data Structure Introduction.
CS 361 – Chapters 8-9 Sorting algorithms –Selection, insertion, bubble, “swap” –Merge, quick, stooge –Counting, bucket, radix How to select the n-th largest/smallest.
Searching and Sorting Recursion, Merge-sort, Divide & Conquer, Bucket sort, Radix sort Lecture 5.
COSC 3101A - Design and Analysis of Algorithms 6 Lower Bounds for Sorting Counting / Radix / Bucket Sort Many of these slides are taken from Monica Nicolescu,
Hashing COMP171. Hashing 2 Hashing … * Again, a (dynamic) set of elements in which we do ‘search’, ‘insert’, and ‘delete’ n Linear ones: lists, stacks,
FALL 2005CENG 213 Data Structures1 Priority Queues (Heaps) Reference: Chapter 7.
Analysis of Algorithms CS 477/677 Lecture 8 Instructor: Monica Nicolescu.
1 Ch. 2: Getting Started. 2 About this lecture Study a few simple algorithms for sorting – Insertion Sort – Selection Sort (Exercise) – Merge Sort Show.
CS6045: Advanced Algorithms Sorting Algorithms. Heap Data Structure A heap (nearly complete binary tree) can be stored as an array A –Root of tree is.
CSE332: Data Abstractions Lecture 12: Introduction to Sorting Dan Grossman Spring 2010.
Onlinedeeneislam.blogspot.com1 Design and Analysis of Algorithms Slide # 1 Download From
Linear Sorting. Comparison based sorting Any sorting algorithm which is based on comparing the input elements has a lower bound of Proof, since there.
19 March More on Sorting CSE 2011 Winter 2011.
CS6045: Advanced Algorithms Sorting Algorithms. Sorting So Far Insertion sort: –Easy to code –Fast on small inputs (less than ~50 elements) –Fast on nearly-sorted.
1 Priority Queues (Heaps). 2 Priority Queues Many applications require that we process records with keys in order, but not necessarily in full sorted.
Lower Bounds & Sorting in Linear Time
Sorting.
CSE332: Data Abstractions Lecture 12: Introduction to Sorting
MCA 301: Design and Analysis of Algorithms
Introduction to Algorithms
Algorithm Design and Analysis (ADA)
Linear Sorting Sections 10.4
Keys into Buckets: Lower bounds, Linear-time sort, & Hashing
Ch8: Sorting in Linear Time Ming-Te Chi
Noncomparison Based Sorting
Lower Bounds & Sorting in Linear Time
Linear Sorting Section 10.4
Linear-Time Sorting Algorithms
Analysis of Algorithms
Ch. 2: Getting Started.
Linear Time Sorting.
Presentation transcript:

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 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[0], B[1], …, B[n-1] together in order … A: B: /.11/.32/.59/ /.45/.90/ 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 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

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

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

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