Lower Bounds for Sorting, Searching and Selection

Slides:



Advertisements
Similar presentations
CPSC 411 Design and Analysis of Algorithms Set 2: Sorting Lower Bound Prof. Jennifer Welch Spring 2011 CPSC 411, Spring 2011: Set 2 1.
Advertisements

Introduction to Algorithms Quicksort
110/6/2014CSE Suprakash Datta datta[at]cse.yorku.ca CSE 3101: Introduction to the Design and Analysis of Algorithms.
Interval Heaps Complete binary tree. Each node (except possibly last one) has 2 elements. Last node has 1 or 2 elements. Let a and b be the elements in.
Analysis of Algorithms
Heapsort O(n lg n) worst case Another design paradigm –Use of a data structure (heap) to manage information during execution of algorithm Comparision-based.
Lower bound: Decision tree and adversary argument
Sorting Comparison-based algorithm review –You should know most of the algorithms –We will concentrate on their analyses –Special emphasis: Heapsort Lower.
Lower Bounds & Models of Computation Jeff Edmonds York University COSC 3101 Lecture 8.
© 2004 Goodrich, Tamassia Sorting Lower Bound1. © 2004 Goodrich, Tamassia Sorting Lower Bound2 Comparison-Based Sorting (§ 10.3) Many sorting algorithms.
CS 253: Algorithms Chapter 8 Sorting in Linear Time Credit: Dr. George Bebis.
CS2420: Lecture 13 Vladimir Kulyukin Computer Science Department Utah State University.
CSC 2300 Data Structures & Algorithms March 27, 2007 Chapter 7. Sorting.
More sorting algorithms: Heap sort & Radix sort. Heap Data Structure and Heap Sort (Chapter 7.6)
2 -1 Analysis of algorithms Best case: easiest Worst case Average case: hardest.
© 2004 Goodrich, Tamassia Sorting Lower Bound1. © 2004 Goodrich, Tamassia Sorting Lower Bound2 Comparison-Based Sorting (§ 10.3) Many sorting algorithms.
CPSC 411, Fall 2008: Set 2 1 CPSC 411 Design and Analysis of Algorithms Set 2: Sorting Lower Bound Prof. Jennifer Welch Fall 2008.
CPSC 411, Fall 2008: Set 2 1 CPSC 311 Analysis of Algorithms Sorting Lower Bound Prof. Jennifer Welch Fall 2009.
Chapter 11: Limitations of Algorithmic Power
Sorting Lower Bound Andreas Klappenecker based on slides by Prof. Welch 1.
DAST 2005 Week 4 – Some Helpful Material Randomized Quick Sort & Lower bound & General remarks…
Chapter 11 Limitations of Algorithm Power Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
MergeSort Source: Gibbs & Tamassia. 2 MergeSort MergeSort is a divide and conquer method of sorting.
Sorting Lower Bound1. 2 Comparison-Based Sorting (§ 4.4) Many sorting algorithms are comparison based. They sort by making comparisons between pairs of.
CSC 213 – Large Scale Programming. Today’s Goals  Review past discussion of data sorting algorithms  Weaknesses of past approaches & when we use them.
Chapter 11 Limitations of Algorithm Power. Lower Bounds Lower bound: an estimate on a minimum amount of work needed to solve a given problem Examples:
CSCE350 Algorithms and Data Structure
Computational Complexity Polynomial time O(n k ) input size n, k constant Tractable problems solvable in polynomial time(Opposite Intractable) Ex: sorting,
Binary Heap.
The Binary Heap. Binary Heap Looks similar to a binary search tree BUT all the values stored in the subtree rooted at a node are greater than or equal.
Data Structure & Algorithm II.  Delete-min  Building a heap in O(n) time  Heap Sort.
The Lower Bounds of Problems
Sorting Lower Bounds Amihood Amir Bar-Ilan University 2014.
1 Lower Bounds Lower bound: an estimate on a minimum amount of work needed to solve a given problem Examples: b number of comparisons needed to find the.
TECH Computer Science Problem: Selection Design and Analysis: Adversary Arguments The selection problem >  Finding max and min Designing against an adversary.
MA/CSSE 473 Day 21 AVL Tree Maximum height 2-3 Trees Student questions?
CSC 213 Lecture 13: Writing Code & Sorting Lowest Bound.
Instructor Neelima Gupta Table of Contents Review of Lower Bounding Techniques Decision Trees Linear Sorting Selection Problems.
Princeton University COS 423 Theory of Algorithms Spring 2001 Kevin Wayne Average Case Analysis.
Lecture 15 Jianjun Hu Department of Computer Science and Engineering University of South Carolina CSCE350 Algorithms and Data Structure.
LIMITATIONS OF ALGORITHM POWER
CSCE 411H Design and Analysis of Algorithms Set 10: Lower Bounds Prof. Evdokia Nikolova* Spring 2013 CSCE 411H, Spring 2013: Set 10 1 * Slides adapted.
1 CSC 421: Algorithm Design & Analysis Spring 2014 Complexity & lower bounds  brute force  decision trees  adversary arguments  problem reduction.
Lecture 9COMPSCI.220.FS.T Lower Bound for Sorting Complexity Each algorithm that sorts by comparing only pairs of elements must use at least 
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.
Heap Sort Uses a heap, which is a tree-based data type Steps involved: Turn the array into a heap. Delete the root from the heap and insert into the array,
Sorting Lower Bounds n Beating Them. Recap Divide and Conquer –Know how to break a problem into smaller problems, such that –Given a solution to the smaller.
Sorting & Lower Bounds Jeff Edmonds York University COSC 3101 Lecture 5.
Lecture 5 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
CSE 589 Applied Algorithms Spring 1999 Prim’s Algorithm for MST Load Balance Spanning Tree Hamiltonian Path.
Decision Trees DEFINITION: DECISION TREE A decision tree is a tree in which the internal nodes represent actions, the arcs represent outcomes of an action,
David Kauchak cs062 Spring 2010
Sorting Lower Bound 4/25/2018 8:49 PM
Decision trees Polynomial-Time
CPSC 411 Design and Analysis of Algorithms
Trees.
CPSC 411 Design and Analysis of Algorithms
Optimal Algorithms Search and Sort.
(2,4) Trees 11/15/2018 9:25 AM Sorting Lower Bound Sorting Lower Bound.
Lower Bound Theory.
Analysis and design of algorithm
Analysis of Algorithms
(2,4) Trees 12/4/2018 1:20 PM Sorting Lower Bound Sorting Lower Bound.
CS200: Algorithm Analysis
Chapter 11 Limitations of Algorithm Power
Lecture 5 Algorithm Analysis
(2,4) Trees 2/28/2019 3:21 AM Sorting Lower Bound Sorting Lower Bound.
Topic 5: Heap data structure heap sort Priority queue
CPSC 411 Design and Analysis of Algorithms
David Kauchak cs302 Spring 2012
Presentation transcript:

Lower Bounds for Sorting, Searching and Selection Lecture 9 Lower Bounds for Sorting, Searching and Selection

Plan Finish Heaps Lower Bounds Selection (Find Min): adversary arguments Sorting: information theory lower bound for comparison based algorithms Searching: ITLB

Finish Heaps Building a heap from an array, in O(n) time

Number of vertices at height h 3 2 1 n/2h+1

Finish Heaps Building a heap from an array, in O(n) time Idea: The leaves are already heaps. Joining two adjacent (sub) heaps with a common root, it suffices to heapify (trickle down from the root). It takes O(h) time (h = distance from the local root to the leaves), for at most n/2h+1 nodes on that level. Total time: S n h/2h+1 = O(n), because S h/2h <2

Recap Linear Time Algorithms: O(n log n) Time Algorithms for sorting: Compute Sum, Product of n numbers Find Min/Max of n numbers Merge 2 arrays of n elements (total) Partition an array into 2 around a pivot O(n log n) Time Algorithms for sorting: Merge Sort Heap Sort Quick Sort (on average) O(log n) Time algorithms: Binary search

Lower Bounds Can we do better? Why not? Lower bounds prove that we cannot hope for a better algorithm, no matter how smart we are. Only very few lower bound proofs are known Most notorious open problems in Theoretical Computer Science are related to proving lower bounds for very important problems Reading: Ch. 13 textbook

Input Lower Bound Compute the sum of n numbers: all numbers must be looked at, otherwise the answer might not be correct Adversary argument: assume there is a smart algorithm which computes the sum without looking at all the n inputs. An adversary goes and modifies the input not looked at, then run the algorithm again. It should give the same answer (because it didn’t look at the modified input data), but this is not the correct answer.

Adversary Arguments Hmmm… Yes! Is a7 < a9? Mr. Algorithm: thinks he has a fast way of solving the problem Ms. Adversary: forces algorithm to work hard by given the worst possible answer

Adversary Arguments The answer is 3 This was the input 4 3 5 2 6 Now try again The answer is 3

Adversary Arguments Wrong! The input was 4 7 5 2 6 this time! The answer is 3 If some questions were not asked, the Adversary tricks the poor Algorithm to try again, on a different input data, with the same answers to the same questions but with a different correct final answer….

Adversary Argument for FindMin: need n-1 questions No. Is a1 < a2? a3=7 a4=6 No. Is a3 < a4? Is a4 > a5? a5=5 Yes. Minimum is a5! Wrong! It is a2!

If less than n-1 questions, the graph of comparisons is disconnected The adversary can re-arrange the data so that the answer is different

Binary Decision Trees ? Yes No Model algorithms based on successive answers to yes/no questions

? Yes No ? Yes No Answer 1 ? Yes No Answer 2 Answer 3 Answer 4

Worst case time: depth of tree A binary tree of depth h has < 2h leaves A binary tree with N leaves must have depth at least log2N This gives a lower bound on the worst case time to find an answer If the number of possible answers is N, then the algorithm MUST ask at least log N questions

Lower Bound for Sorting Number of possible sorted orders = number of all possible permutations of n elements = n! Hence any comparison-based algorithm for sorting must take at least log n! = O(n log n) time

Lower Bound for Searching In-class exercise How many possible answers for the searching question? What is the log of that? What is the lower bound for searching?