Lecture 5 Algorithm Analysis

Slides:



Advertisements
Similar presentations
Sorting in Linear Time Introduction to Algorithms Sorting in Linear Time CSE 680 Prof. Roger Crawfis.
Advertisements

Analysis of Algorithms
Analysis of Algorithms CS 477/677 Linear Sorting Instructor: George Bebis ( Chapter 8 )
Non-Comparison Based Sorting
MS 101: Algorithms Instructor Neelima Gupta
Mudasser Naseer 1 5/1/2015 CSC 201: Design and Analysis of Algorithms Lecture # 9 Linear-Time Sorting Continued.
CSE332: Data Abstractions Lecture 14: Beyond Comparison Sorting Dan Grossman Spring 2010.
Lower bound for sorting, radix sort COMP171 Fall 2005.
CS Section 600 CS Section 002 Dr. Angela Guercio Spring 2010.
Lower bound for sorting, radix sort COMP171 Fall 2006.
Lecture 5: Linear Time Sorting Shang-Hua Teng. Sorting Input: Array A[1...n], of elements in arbitrary order; array size n Output: Array A[1...n] of the.
CS 253: Algorithms Chapter 8 Sorting in Linear Time Credit: Dr. George Bebis.
Comp 122, Spring 2004 Keys into Buckets: Lower bounds, Linear-time sort, & Hashing.
Comp 122, Spring 2004 Lower Bounds & Sorting in Linear Time.
Lecture 5: Master Theorem and Linear Time Sorting
CSE 326: Data Structures Sorting Ben Lerner Summer 2007.
Analysis of Algorithms CS 477/677
David Luebke 1 7/2/2015 Linear-Time Sorting Algorithms.
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
David Luebke 1 10/13/2015 CS 332: Algorithms Linear-Time Sorting Algorithms.
CSC 41/513: Intro to Algorithms Linear-Time Sorting Algorithms.
Introduction to Algorithms Jiafen Liu Sept
CSE332: Data Abstractions Lecture 14: Beyond Comparison Sorting Dan Grossman Spring 2012.
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.
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,
1 Algorithms CSCI 235, Fall 2015 Lecture 17 Linear Sorting.
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.
Linear Sorting. Comparison based sorting Any sorting algorithm which is based on comparing the input elements has a lower bound of Proof, since there.
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.
Lecture 3 Sorting and Selection. Comparison Sort.
Lecture 5 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
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.
Lower Bounds & Sorting in Linear Time
Sorting Lower Bound 4/25/2018 8:49 PM
Decision trees Polynomial-Time
Linear-Time Sorting Continued Medians and Order Statistics
MCA 301: Design and Analysis of Algorithms
Introduction to Algorithms
Algorithm Design and Analysis (ADA)
CS200: Algorithm Analysis
(2,4) Trees 11/15/2018 9:25 AM Sorting Lower Bound Sorting Lower Bound.
Lecture 5 Algorithm Analysis
Linear Sorting Sections 10.4
Keys into Buckets: Lower bounds, Linear-time sort, & Hashing
Ch8: Sorting in Linear Time Ming-Te Chi
Lecture 5 Algorithm Analysis
Linear Sort "Our intuition about the future is linear. But the reality of information technology is exponential, and that makes a profound difference.
(2,4) Trees 12/4/2018 1:20 PM Sorting Lower Bound Sorting Lower Bound.
Chapter 8: Sorting in Linear Time
CS200: Algorithm Analysis
Linear Sorting Sorting in O(n) Jeff Chastine.
Linear Sort "Our intuition about the future is linear. But the reality of information technology is exponential, and that makes a profound difference.
Lower Bounds & Sorting in Linear Time
Linear Sorting Section 10.4
Linear-Time Sorting Algorithms
Lecture 3 Sorting and Selection
(2,4) Trees 2/28/2019 3:21 AM Sorting Lower Bound Sorting Lower Bound.
Topic 5: Heap data structure heap sort Priority queue
Lower bound for sorting, radix sort
Algorithms CSCI 235, Spring 2019 Lecture 18 Linear Sorting
Chapter 8: Sorting in Linear Time
Chapter 8: Overview Comparison sorts: algorithms that sort sequences by comparing the value of elements Prove that the number of comparison required to.
CS 583 Analysis of Algorithms
Lecture 5 Algorithm Analysis
Presentation transcript:

Lecture 5 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea

Lower Bounds for Sorting

Decision-tree for insertion sort on 3 elements Algorithm Analysis

Decision tree Abstraction of any comparison sort. Represents comparisons made by a specific sorting algorithm on inputs of a given size. Abstracts away everything else: control and data movement. We are counting only comparisons. Algorithm Analysis

Decision tree (cont.) How many leaves on the decision tree? There are ≥ n! leaves, because every permutation appears at least once. Q: What is the length of the longest path from root to leaf? A: Depends on the algorithm. Examples Insertion sort: Θ(n2) Merge sort: Θ(n lg n) Algorithm Analysis

Decision tree (cont.) Theorem Any decision tree that sorts n elements has height Ω(n lg n). Proof: Take logs: h ≥ lg(n!) Algorithm Analysis

Linear Time Sorting

Counting sort Depends on a key assumption: Numbers to be sorted are integers in {0, 1, . . . , k}. Input: A[1 . . n], where A[ j ] ∈ {0, 1, . . . , k} for j = 1, 2, . . . , n. Array A and values n and k are given as parameters. Output: B[1 . . n], sorted. B is assumed to be already allocated and is given as a parameter. Auxiliary storage: C[0 . . k] Algorithm Analysis

Counting sort - Pseudocode Algorithm Analysis

Counting sort – Final Words Counting sort is stable (keys with same value appear in same order in output as they did in input) because of how the last loop works. Analysis: Θ(n + k), which is Θ(n) if k = O(n). Algorithm Analysis

Radix Sort Key idea: Sort least significant digits first. To sort numbers of d digits: Algorithm Analysis

Example Algorithm Analysis

Radix Sort - Correctness Induction on number of passes (i in Pseudo code). Assume digits 1, 2, . . . , i − 1 are sorted. Show that a stable sort on digit i delivers some sorted result: If 2 digits in position i are different, ordering by position i is correct, and positions 1, . . . , i − 1 are irrelevant. If 2 digits in position i are equal, numbers are already in the right order (by inductive hypothesis). The stable sort on digit i leaves them in the right order. Algorithm Analysis

Radix Sort Analysis Assume that we use counting sort as the intermediate sort. Θ(n + k) per pass (digits in range 0, . . . , k) d passes Θ(d(n + k)) total If k = O(n), time = Θ(dn). Algorithm Analysis

How to break each key into digits? n words. b bits/word. Break into r -bit digits. Have d = Use counting sort, k = 2r − 1. Example: 32-bit words, 8-bit digits. b = 32, r = 8, d = 32/8 = 4, k = 28 − 1 = 255 Time = Algorithm Analysis

How to choose r? Balance b/r and n + 2r . Choosing r ≈ lg n gives us If we choose r < lg n, then b/r > b/ lg n, and n + 2r term doesn’t improve. If we choose r > lg n, then n + 2r term gets big. Example: r = 2 lg n ⇒ 2r = 22 lgn = (2lg n)2 = n2. Algorithm Analysis