A Lower Bound for Comparison Sort

Similar documents
Animation Demos. Shows time complexities on best, worst and average case.

Chapter 7: Sorting 7.1. Original

Divide & conquer. Which works better for multi-cores: insertion sort or merge sort? Why?

Introduction to. Algorithms. Lecture 10. Prof. Constantinos Daskalakis CLRS

CSE 21 Practice Final Exam Winter 2016

ECE 242 Data Structures and Algorithms. Simple Sorting II. Lecture 5. Prof.

Animation Demos. Shows time complexities on best, worst and average case.

DATA STRUCTURES USING C

Programming Abstractions

Previous Lecture. How can computation sort data faster for you? Sorting Algorithms: Speed Comparison. Recursive Algorithms 10/31/11

Introduction to Algorithms / Algorithms I Lecturer: Michael Dinitz Topic: Algorithms and Game Theory Date: 12/4/14

lecture notes September 2, Batcher s Algorithm

More Great Ideas in Theoretical Computer Science. Lecture 1: Sorting Pancakes

Algorithms and Data Structures CS 372. The Sorting Problem. Insertion Sort - Summary. Merge Sort. Input: Output:

CS 758/858: Algorithms

Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute. Module 6 Lecture - 37 Divide and Conquer: Counting Inversions

Introduction to. Algorithms. Lecture 10. Prof. Piotr Indyk

CSE465, Spring 2009 March 16 1

Lecture 7: The Principle of Deferred Decisions

CSE 373 DECEMBER 4 TH ALGORITHM DESIGN

CS3334 Data Structures Lecture 4: Bubble Sort & Insertion Sort. Chee Wei Tan

1111: Linear Algebra I

Lecture 2. 1 Nondeterministic Communication Complexity

MITOCW 7. Counting Sort, Radix Sort, Lower Bounds for Sorting

Lecture 20: Combinatorial Search (1997) Steven Skiena. skiena

COS 226 Algorithms and Data Structures Fall Midterm Exam

COS 226 Algorithms and Data Structures Fall Midterm Exam

((( ))) CS 19: Discrete Mathematics. Please feel free to ask questions! Getting into the mood. Pancakes With A Problem!

Lecture5: Lossless Compression Techniques

Algorithms. Abstract. We describe a simple construction of a family of permutations with a certain pseudo-random

Block Ciphers Security of block ciphers. Symmetric Ciphers

Lecture 12: Divide and Conquer Algorithms. Divide and Conquer Algorithms

The Complexity of Sorting with Networks of Stacks and Queues

Counting in Algorithms

Fast Sorting and Pattern-Avoiding Permutations

Olympiad Combinatorics. Pranav A. Sriram

CSE373: Data Structure & Algorithms Lecture 23: More Sorting and Other Classes of Algorithms. Nicki Dell Spring 2014

Extended Introduction to Computer Science CS1001.py

Game Theory and Randomized Algorithms

Partitions and Permutations

CS101 Lecture 28: Sorting Algorithms. What You ll Learn Today

Selective Families, Superimposed Codes and Broadcasting on Unknown Radio Networks. Andrea E.F. Clementi Angelo Monti Riccardo Silvestri

Decision Mathematics practice paper

Sec 5.1 The Basics of Counting

Collectives Pattern. Parallel Computing CIS 410/510 Department of Computer and Information Science. Lecture 8 Collective Pattern

Hypercube Networks-III

Content. 1 Understanding and analyzing algorithms. 2 Using graphs and graph algorithms

Collectives Pattern CS 472 Concurrent & Parallel Programming University of Evansville

Yale University Department of Computer Science

Lecture Notes 3: Paging, K-Server and Metric Spaces

arxiv: v1 [cs.cc] 21 Jun 2017

GENERALIZATION: RANK ORDER FILTERS

Sensor Network Gossiping or How to Break the Broadcast Lower Bound

CS510 \ Lecture Ariel Stolerman

RMT 2015 Power Round Solutions February 14, 2015

What is a Sorting Function?

MITOCW watch?v=cnb2ladk3_s

Tiling Problems. This document supersedes the earlier notes posted about the tiling problem. 1 An Undecidable Problem about Tilings of the Plane

Stanford University CS261: Optimization Handout 9 Luca Trevisan February 1, 2011

MITOCW watch?v=3e1zf1l1vhy

Compressing Pattern Databases

How Many Mates Can a Latin Square Have?

Randomized Algorithms

Game Theory and Algorithms Lecture 3: Weak Dominance and Truthfulness

Tile Complexity of Assembly of Length N Arrays and N x N Squares. by John Reif and Harish Chandran

COMP Online Algorithms. Paging and k-server Problem. Shahin Kamali. Lecture 11 - Oct. 11, 2018 University of Manitoba

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Algorithmic Game Theory Date: 12/6/18

Plan. Related courses. A Take-Away Game. Mathematical Games , (21-801) - Mathematical Games Look for it in Spring 11

CS431 homework 2. 8 June Question 1 (page 54, problem 2.3). Is lg n = O(n)? Is lg n = Ω(n)? Is lg n = Θ(n)?

More on recursion. Fundamentals of Computer Science Keith Vertanen

Sec$on Summary. Permutations Combinations Combinatorial Proofs

Ma/CS 6a Class 16: Permutations

Network-building. Introduction. Page 1 of 6

On Symmetric Key Broadcast Encryption

Improving Text Indexes Using Compressed Permutations

Anavilhanas Natural Reserve (about 4000 Km 2 )

MITOCW R7. Comparison Sort, Counting and Radix Sort

UPenn NETS 412: Algorithmic Game Theory Game Theory Practice. Clyde Silent Confess Silent 1, 1 10, 0 Confess 0, 10 5, 5

Random. Bart Massey Portland State University Open Source Bridge Conf. June 2014

MITOCW watch?v=krzi60lkpek

On the size of sets of permutations with bounded VC-dimension

Parking and Railroad Cars

Last update: March 9, Game playing. CMSC 421, Chapter 6. CMSC 421, Chapter 6 1

Sorting. APS105: Computer Fundamentals. Jason Anderson

Greedy Algorithms. Kleinberg and Tardos, Chapter 4

CSE 1400 Applied Discrete Mathematics Permutations

NOTES ON SEPT 13-18, 2012

Game-playing AIs: Games and Adversarial Search FINAL SET (w/ pruning study examples) AIMA

Bounds for Cut-and-Paste Sorting of Permutations

Some recent results and some open problems concerning solving infinite duration combinatorial games. Peter Bro Miltersen Aarhus University

Lecture 20 November 13, 2014

DISCRETE STRUCTURES COUNTING

Discrete Structures for Computer Science

Notes for Recitation 3

Merge Sort. Note that the recursion bottoms out when the subarray has just one element, so that it is trivially sorted.

SPACE-EFFICIENT ROUTING TABLES FOR ALMOST ALL NETWORKS AND THE INCOMPRESSIBILITY METHOD

Signal Recovery from Random Measurements

PERMUTATIONS AS PRODUCT OF PARALLEL TRANSPOSITIONS *

Fermat s little theorem. RSA.

MA 524 Midterm Solutions October 16, 2018

Transcription:

A Lower Bound for Comparison Sort Pedro Ribeiro DCC/FCUP 2014/2015 Pedro Ribeiro (DCC/FCUP) A Lower Bound for Comparison Sort 2014/2015 1 / 9

On this lecture Upper and lower bound problems Notion of comparison-based sort An Ω(n log n) worst-case bound for a deterministic comparison 2 player game view of algorithm analysis Pedro Ribeiro (DCC/FCUP) A Lower Bound for Comparison Sort 2014/2015 2 / 9

Upper Bound Problem One typical question when designing algorithms is: given some problem X, can we construct an algorithm that runs in time O(f (n)) on inputs of size n? This can be seen as an upper bound problem, and our goal is to make g(n) as low as possible. Pedro Ribeiro (DCC/FCUP) A Lower Bound for Comparison Sort 2014/2015 3 / 9

Lower Bound Problem In this lecture, the question is different: given some problem X, what is g(n) such that any algorithm must take time Ω(g(n)) on inputs of size n? This can be seen as an lower bound problem, and our goal is to make g(n) as high as possible. Lower bound help understand the intrinsic difficulty of the problem and how close we are to the best possible solution. Pedro Ribeiro (DCC/FCUP) A Lower Bound for Comparison Sort 2014/2015 4 / 9

Lower Bound Problem For today we will consider the class of comparison-based sorting algorithms. These are sorting algorithms that operate only by comparing elements and moving them around based on the result of these comparisons Comparison-Based Sorting Algorithm A comparison-based sorting algorithm takes as input an array [a 1, a 2,..., a n ] with n items, and can only gain information about the items by comparing pairs of them. Each comparison ( is a i < a j? ) returns YES or NO. In the end, the algorithm must output a permutation of the input in which all items are in sorted order. Ex: QuickSort, MergeSort, HeapSort, InsertionSort, SelectionSort or BubbleSort are all comparison-based sorting algorithms. Pedro Ribeiro (DCC/FCUP) A Lower Bound for Comparison Sort 2014/2015 5 / 9

Lower Bound for the Deterministic Case Theorem Any deterministic comparison-based sorting algorithm must perform Ω(n log n) comparisons to sort n elements in the worst case. We will now prove this theorem, by showing that given any deterministic comparison-based sorting algorithm A, for all n 2 there exists an input I of size n such that A makes at least log 2 (n!) = Ω(n log n) comparisons to sort I. Note that we need to prove for any possible deterministic algorithm, and not for a specific choice of pivot on QuickSort, or for a specific merge operation on MergeSort. Pedro Ribeiro (DCC/FCUP) A Lower Bound for Comparison Sort 2014/2015 6 / 9

20 questions games Your goal is to determine the correct ordering of n elements (that you do not know in advance) Imagine you can ask me questions about the result of comparing a pair of elements I m answering this questions with the goal of delaying as much as possible your final answer How many questions do you need to ask? Pedro Ribeiro (DCC/FCUP) A Lower Bound for Comparison Sort 2014/2015 7 / 9

Proving the Ω(n log n) bound There are n! permutations that could be the output of the algorithm For each of these permutations, there is an input for which that permutation is the only correct answer Let S be set of permutations that are consistent with the questions already made Initially, S = n! What happens when you start asking questions? Pedro Ribeiro (DCC/FCUP) A Lower Bound for Comparison Sort 2014/2015 8 / 9

Proving the Ω(n log n) bound A comparison will answer YES or NO This answer will split the permutations still left in S in two groups Now suppose the adversary answering the question will always choose the answer leading to the largest group This means at each time we can only cut S by a factor of 2 By design, the algorithm can only stop when S = 1, so that it knows what permutation to output This means the algorithm must make log 2 (n!) questions! (i.e., comparisons) log 2 (n!) = log 2 (n)+log 2 (n 1)+log 2 (n 2)+...+log 2 (2) = Ω(n log n) (we could use Stirling s Approximation to prove this last step) Pedro Ribeiro (DCC/FCUP) A Lower Bound for Comparison Sort 2014/2015 9 / 9