Lower and Upper Bound Theory. Prof:Dr. Adnan YAZICI Dept. of Computer Engineering Middle East Technical Univ. Ankara - TURKEY
|
|
- Samson Fisher
- 5 years ago
- Views:
Transcription
1 Lower and Upper Bound Theory Prof:Dr. Adnan YAZICI Dept. of Computer Engineering Middle East Technical Univ. Ankara - TURKEY 1
2 Lower and Upper Bound Theory How fast can we sort? Lower-Bound Theory can help us answer this question. Most of the sorting algorithms are comparison sorts: only use comparisons to determine the relative order of elements. Examples: insertion sort, merge sort, quicksort, heapsort. The best worst-case running time that we ve seen for comparison sorting is O(nlgn). Is O(nlgn) the best we can do? 2
3 Lower and Upper Bound Theory Lower Bound, L(n), is a property of the specific problem, i.e. sorting problem, MST, matrix multiplication, not of any particular algorithm solving that problem. Lower bound theory says that no algorithm can do the job in fewer than L(n) time units for arbitrary inputs. For example, every comparison-based sorting algorithm must take at least L(n), nlgn, time in the worst case. L(n) is the minimum over all possible algorithms, of the maximum complexity. 3
4 Lower and Upper Bound Theory Upper bound theory says that for any arbitrary inputs, we can always sort in time at most U(n). How long it would take to solve a problem using one of the known algorithms with worst-case input gives us a upper bound. U(n) is the minimum over all known algorithms, of the maximum complexity. For example: Finding the maximum element in an unsorted array is U(n), O(n). Both upper and lower bounds are minima over the maximum complexity of inputs of size n. Improving an upper bound means finding a new algorithm with better worst-case performance. The ultimate goal is to make these two functions coincide. When this is done, the optimal algorithm will have L(n) = U(n). 4
5 Examples: Lower Bounds an estimate on a minimum amount needed to multiply two n-by-n matrices of work needed to solve a given problem. number of comparisons needed to find the mean element in a set of n numbers. number of comparisons needed to sort an array of size n. number of comparisons necessary for searching in a sorted array. number of multiplications for n-digit integers. 5
6 Lower Bounds (cont.) Lower bound can be an exact count an efficiency class (Ω) Tight lower bound: there exists an algorithm with the same efficiency as the lower bound Problem Lower bound Tightness sorting Ω(nlogn) yes searching in a sorted array Ω(logn) yes element uniqueness Ω(nlogn) yes n-digit integer multiplication Ω(n) unknown multiplication of n-by-n matrices Ω(n 2 ) unknown 6
7 Methods for Establishing Lower Bounds There are few techniques for finding lower bounds: trivial lower bound information-theory decision tree problem reduction adversary arguments 7
8 Trivial Lower Bound Method 1) Trivial Lower Bounds: For many problems it is possible to easily observe that a lower bound identical to number of inputs (n) exists, (or possibly outputs) to the problem. The method is based on counting the number of items that must be processed in input and generated as output. Note that any algorithm must, at least, read its inputs and write its outputs. Example-1: Multiplication of a pair of nxn matrices requires that 2n 2 inputs be examined and n 2 outputs be computed, and the lower bound for this matrix multiplication problem is therefore Ω(n 2 ). 8
9 Trivial Lower Bound Method Example: Finding maximum (or minimum) of unordered array requires examining each input, so it is Ω(n). A simple counting arguments shows that any comparison-based algorithm for finding the maximum value of an element in a list of size n must perform at least n-1 comparisons for any input. Comment: This method may and may not be useful be careful in deciding how many elements must be processed 9
10 Information Theory The information theory method establishing lower bounds by computing the limitations on information gained by a basic operation and then showing how much information is required before a given problem is solved. This is used to show that any possible algorithm for solving a problem must do some minimal amount of work. The most useful principle of this kind is that the outcome of a comparison between two items yields one bit of information. 10
11 Lower and Upper Bound Theory Example: For the problem of searching an ordered list with n elements for the position of a particular item, <a,b,c,d> > <a,b> <c,d> > > a b c d For any outcome, at least 2 comparisions, therefore, 2 bits of information are necessary. 11
12 Information Theory Example: The lower bound of the problem of searching an ordered list with n elements for the position of a particular item is Θ(lgn). Proof: There are n possible outcomes, input strings In this case lgn comparisons are necessary, If a comparison between two items yields one bit of information, then unique identification of an index in the list requires lgn bits. Therefore, lgn bits of information are necessary to specify one of the n possibilities. 12
13 Information Theory Example-2: By using information theory, the lower bound for the problem of comparison-based sorting problem. input > > > <1,2,3> 111 > <2,1,3> > <1,3,2> <3,1,2> <2,3,1> <3,2,1> 000 Figure: There are 3! = 6 possible permutations of the n input elements, so lgn! bits are required for lgn! comparisons for sorting n things. 13
14 Information Theory Example: By using information theory, the lower bound for the problem of comparison-based sorting problem is Θ(nlgn) Proof: If we only know that the input is orderable, then there are n! possible outcomes each of the n! permutations of n things. Within the comparison-swap model, we can only use comparisons to derive information Since each comparison only yields one bit of information, the question is what the minimum number of bits of information needed to allow n! different outcomes is, which is lgn! bits. 14
15 Information Theory How fast lgn! grow? We can bind n! from above by overestimating every term of the product, and bind it below by underestimating the first n/2 terms. n/2*n/2* *n/2* *2*1 n*(n-1)* *2*1 n* n* *n (n/2) n/2 n! n n ½(nlgn-n) lgn! nlgn ½nlgn- ½ n lgn! nlgn ½nlgn lgn! nlgn This follows that lgn! Θ(nlgn) 15
16 Decision-tree model This method can model the execution of any comparison based problem. One tree for each input size n. View the algorithm as splitting whenever it compares two elements. The decision tree contains the comparisons along all possible instruction traces. The running time of the algorithm = the length of the path taken. 16
17 Decision-tree model Decision tree is a convenient model of algorithms involving comparisons in which: Internal nodes represent comparisons leaves represent outcomes. There must be n internal nodes in all of these trees corresponding to the n possible successful occurrences of x in A. Because every leaf in a valid decision tree must be reachable, the worst-case number of comparisons done by such a tree is the number of nodes in the longest path from the root to a leaf in the decision tree consisting of the comparison nodes. Worst-case running time = the length of the longest path of tree = the height of tree. 17
18 Decision-tree Model for Searching Example: Comparison-based searching problem Proof: Let us consider all possible decision trees which model algorithms to solve the searching problem. FIND(n) is bounded below by the distance of the longest path from the root to a leaf in such a tree. 18
19 Decision-tree model for Searching Height=log 2 n x:a( lg(n+1)/2 ) > x:a( lg(n+1)/4 ) x:a( lg(3n+1)/4 ) >. > x:a(1). x:a( lg(n+1)/4-1) x:a( lg(n+1)/4 +1) x:a(n) > > > > Return Failure Return Failure Return Failure Return Failure A decision tree for a search algorithm 19
20 Decision-tree Model for Search on Sorted Elements 3 < > = Height=log2(7)=3 < > < = > = < = > < > < > = = < = > F 0 F F 2 F F 4 F F 6 F Example decision tree for search on sorted list <0,1,2,3,4,5,6> 20
21 Decision-tree Model for Searching Example: Comparison-based searching problem A decision tree, with n leaves and height h, n 2 h. Indeed, a decision tree of height h with largest number of leaves has all its leaves on the last level. Hence, the largest number of leaves in such a tree is 2 h. FIND(n) = h log (n) Since, n 2 h and. Such a longest path is Θ(lgn). Therefore, the lower bound for comparisonbased searching on ordered input is Θ(lgn). 21
22 Decision-tree model for Searching Return(A(1)) = x:a(1) = Return(A(2)) x:a(2) Height = n x:a(n) = Return(A(n)) Return(A(0)) A decision tree for search on unsorted list The number of comparisons in the worst-case is equal to the height (h) of the algorithm s decision tree. h n and h Ω(n). 22
23 Decision-tree for Search on Unsorted Elements Height = 5 4 = 4 1 = 1 5 = 5 3 = 3 2 = 2 0 = 0 F Example decision tree for search on unsorted list <4,1,5,3,2,0>, that is, h = n. Therefore, the lower bound for comparisonbased searching on unordered input is Θ(n). 23
24 Decision-tree model for Sorting a1,a2,a3 yes a1<a2 no a1a2a3 a2a1a3 yes a2<a3 no yes a1<a3 no a1<a2<a3 yes a1a3a2 a1<a3 no a2<a1<a3 yes a2a3a1 a2<a3 no a1<a3<a2 a3<a1<a2 a2<a3<a1 a3<a2<a1 Each internal node is labelled for i,j element-of {1,2,...,n}. The left subtree shows subsequent comparisons if ai aj. The right subtree shows subsequent comparisons if ai aj. 24
25 Decision-tree model for sorting Each permutation represents a distinct sorted order and the tree muct have n! leaves. Since a binary tree of height h has no more than 2 h leaves, we have n! 2 h. 25
26 26
27 Problem Reduction Prob. 1 (to be solved) (reduction) Prob 2 (solvable by Alg.A) Prob 2 (solvable by Alg.A) (Alg.A) Soln. to Prob. 1 Another elegant means of proving a lower bound on a problem P is to show that problem P is at least as hard as another problem Q with a known lower bound. We need to reduce Q to P (not P to Q). In other words, we should show that an arbitrary instance of problem Q can be transformed (in a reasonably efficient way) to an instance of problem P, so that any algorithm solving P would also solve Q as well. Then a lower bound for Q will be a lower bound for P. Prob. Q (LB is known) (reduction) Prob.P (whose LB to be known) 27
28 Problem Reduction Example: Euclidean minimum spanning tree (MST) problem: Given n points in the Cartesian plane construct an Euclidian MST, whose vertices are the given points. As a problem with a known LB, we use the element uniqueness problem (EUP), whose LB is known as Ω(nlgn). The reduction is as follows: Transform any set x 1,x 2,,x n of n real numbers into a set of points in the Cartesian plane by simply adding 0 as the points s y coordinate: (x 1,0), (x 2,0),,(x n,0). This reduction implies that Ω(nlgn) is a LB for the Euclidian MST problem as well. Solution of EUP can now be found using the solution of Euclidean MST: Let T be any Euclidean MST found for this set of points, (x 1,0), (x 2,0),,(x n,0). Since T must contain a shortest edge, checking whether T contains a zero length edge will answer the question about uniqueness of the given numbers, x 1,x 2,,x n. 28
29 Example for reduction: Convex Hull Example: Computing the convex hull in Computational Geometry is perhaps the most basic, elementary function on a set of points. A Convex Hull is the smallest convex polygon that contains every point of the set S. A polygon P is convex if and only if, for any two points A and B, inside the polygon, then the line segment AB is inside P. 29
30 Example for reduction Convex Hull (cont.) One way to visualize a convex hull is to put a "rubber band" around all the points, and let it wrap as tight as it can. We can think of a rubber balloon for the threedimensional case. 30
31 Example for reduction Convex Hull (cont.) Theorem: The comparison-based sorting problem is transformable (in linear time) to the convex hull problem, therefore; the problem of finding the ordered convex hull of n points in the plane requires Ω(nlogn) time. That is, LB of the problem of convex hull is also Ω(nlogn). Proof: First we introduce a proposition: Proposition (Lower Bounds via Transformability): If a problem A is known to require T(n) time and A is τ(n)- transformable to B (A τ(n) B) then B requires at least T(n) O(τ(n)) time. 31
32 Example for reduction Convex Hull (cont.) Reduction: Given n real sorted numbers x 1, x 2,..., x n, all positive, we determine corresponding points (x 1,x 12 ), (x 2,x 22 ),, (x n,x n2 ). All of these points lie on the parabola y = x 2 and they all together result in a convex hull. Since LB of comparison-based sorting problem is known, Ω(nlogn), the LB of the problem of convex hull is also Ω(nlogn). So, when n real numbers x 1, x 2,..., x n are given, we can show how a convex hull algorithm can be used to sort these numbers with only linear overhead. The convex hull of this set, in standard form, will consist of a list of the points sorted. One pass through the list will enable us to read off the x i in order (in sorted form). 32
33 Example for reduction Convex Hull (cont.) y y = x 2 * * * * * x 1 x 2 x 3 x 4 x 5 x 6 * x Sorted 33
34 Example for reduction Convex Hull (cont.) Proposition (Upper Bounds via Transformability): If a problem B can be solved in T(n) time and problem A is τ(n)- transformable to B (A τ(n) B) then A can be solved in at most T(n) + O(τ(n)) time. 34
35 Oracles and Adversary Arguments Another technique for obtaining LBs consists of making use of an oracle or adversary arguments. Adversary arguments establish (worst-case) lower bounds by dynamically creating inputs to a given algorithm that force the algorithm to perform many basic operations. In order to derive a good LB, the adversary tries its best to cause the algorithm to work as hard as it might. We only require that the adversary gives answers that are consistent and truthful. We also assume that the algorithm uses a basic operation when querying the adversary. Clever adversaries force any given algorithm to make many queries before the algorithm has enough information to output the solution. LBs for the worst-case complexity are then obtained by counting the number of basic operations that the adversary forces the algorithm to perform. 35
36 Oracle and Adversary Arguments Adversary argument: a method of proving a lower bound by playing role of adversary that makes algorithm work the hardest by adjusting input. LBs for the worst-case complexity are then obtained by counting the number of basic operations that the adversary forces the algorithm to perform. Example-1: Guessing a number between 1 and n with yes/no questions. Adversary:Put the number in a larger of the two subsets generated by last question. For example; Adversary (or Oracle) knows your guess, which in the order of <4,7,9,4,8>. So, you put the the numbers in that order, 8 at the end, to force the algorithm the hardest way. That way, output is guessed as 8 only after n-1 guesses. That means the lower bound for this problem is Ω(n). Example-2: Merging two sorted lists of size n a 1 < a 2 < < a n and b 1 < b 2 < < b n Adversary: a i < b j iff i < j. There output: b 1 < a 1 < b 2 < a 2 < < b n < a n requires 2n-1 comparisons of adjacent elements. That means the lower bound for this problem is Ω(n). 36
37 Oracles and Adversary Arguments Example: (Merging Problem) Given the sets A(1:m) and B(1:n), where the items in A and in B are sorted. Investigate lower bounds for algorithms merging these two sets to give a single sorted set. Assume that all of the m+n elements are distinct and A(1)<A(2)< <A(m) and B(1) < B(2) < < B(n). Elementary combinatorics tells us that there are C((m+n), n)) ways that the A s and B s may merge together while still preserving the ordering within A and B. Thus, if we use comparison trees as our model for merging algorithms, then there will be C((m+n), n)) external nodes and therefore log C((m+n), m) comparisons are required by any comparison-based merging algorithm in worst-case. If we let MERGE(m,n) be the minimum number of comparisons need to merge m items with n items then we have the inequality log C((m+n), m) MERGE(m,n) m+n-1. The upper bound and lower bound can get arbitrarily far apart as m gets much smaller than n. 37
Lower bound for comparison-based sorting
COMP3600/6466 Algorithms 2018 Lecture 8 1 Lower bound for comparison-based sorting Reading: Cormen et al, Section 8.1 and 8.2 Different sorting algorithms may have different running-time complexities.
More informationComparison Based Sorting Algorithms. Algorithms and Data Structures: Lower Bounds for Sorting. Comparison Based Sorting Algorithms
Comparison Based Sorting Algorithms Algorithms and Data Structures: Lower Bounds for Sorting Definition 1 A sorting algorithm is comparison based if comparisons A[i] < A[j], A[i] A[j], A[i] = A[j], A[i]
More informationAlgorithms and Data Structures: Lower Bounds for Sorting. ADS: lect 7 slide 1
Algorithms and Data Structures: Lower Bounds for Sorting ADS: lect 7 slide 1 ADS: lect 7 slide 2 Comparison Based Sorting Algorithms Definition 1 A sorting algorithm is comparison based if comparisons
More informationChapter 8 Sort in Linear Time
Chapter 8 Sort in Linear Time We have so far discussed several sorting algorithms that sort a list of n numbers in O(nlog n) time. Both the space hungry merge sort and the structurely interesting heapsort
More informationCSE373: Data Structure & Algorithms Lecture 21: More Comparison Sorting. Aaron Bauer Winter 2014
CSE373: Data Structure & Algorithms Lecture 21: More Comparison Sorting Aaron Bauer Winter 2014 The main problem, stated carefully For now, assume we have n comparable elements in an array and we want
More informationThe complexity of Sorting and sorting in linear-time. Median and Order Statistics. Chapter 8 and Chapter 9
Subject 6 Spring 2017 The complexity of Sorting and sorting in linear-time Median and Order Statistics Chapter 8 and Chapter 9 Disclaimer: These abbreviated notes DO NOT substitute the textbook for this
More informationCSE 3101: Introduction to the Design and Analysis of Algorithms. Office hours: Wed 4-6 pm (CSEB 3043), or by appointment.
CSE 3101: Introduction to the Design and Analysis of Algorithms Instructor: Suprakash Datta (datta[at]cse.yorku.ca) ext 77875 Lectures: Tues, BC 215, 7 10 PM Office hours: Wed 4-6 pm (CSEB 3043), or by
More informationDesign and Analysis of Algorithms
Design and Analysis of Algorithms CSE 5311 Lecture 8 Sorting in Linear Time Junzhou Huang, Ph.D. Department of Computer Science and Engineering CSE5311 Design and Analysis of Algorithms 1 Sorting So Far
More informationData Structures and Algorithms Week 4
Data Structures and Algorithms Week. About sorting algorithms. Heapsort Complete binary trees Heap data structure. Quicksort a popular algorithm very fast on average Previous Week Divide and conquer Merge
More informationData Structures and Algorithms Chapter 4
Data Structures and Algorithms Chapter. About sorting algorithms. Heapsort Complete binary trees Heap data structure. Quicksort a popular algorithm very fast on average Previous Chapter Divide and conquer
More informationComputer Science 385 Analysis of Algorithms Siena College Spring Topic Notes: Divide and Conquer
Computer Science 385 Analysis of Algorithms Siena College Spring 2011 Topic Notes: Divide and Conquer Divide and-conquer is a very common and very powerful algorithm design technique. The general idea:
More informationLecture: Analysis of Algorithms (CS )
Lecture: Analysis of Algorithms (CS583-002) Amarda Shehu Fall 2017 Amarda Shehu Lecture: Analysis of Algorithms (CS583-002) Sorting in O(n lg n) Time: Heapsort 1 Outline of Today s Class Sorting in O(n
More informationHow fast can we sort? Sorting. Decision-tree example. Decision-tree example. CS 3343 Fall by Charles E. Leiserson; small changes by Carola
CS 3343 Fall 2007 Sorting Carola Wenk Slides courtesy of Charles Leiserson with small changes by Carola Wenk CS 3343 Analysis of Algorithms 1 How fast can we sort? All the sorting algorithms we have seen
More informationLecture 3. Brute Force
Lecture 3 Brute Force 1 Lecture Contents 1. Selection Sort and Bubble Sort 2. Sequential Search and Brute-Force String Matching 3. Closest-Pair and Convex-Hull Problems by Brute Force 4. Exhaustive Search
More informationHow many leaves on the decision tree? There are n! leaves, because every permutation appears at least once.
Chapter 8. Sorting in Linear Time Types of Sort Algorithms The only operation that may be used to gain order information about a sequence is comparison of pairs of elements. Quick Sort -- comparison-based
More informationEECS 2011M: Fundamentals of Data Structures
M: Fundamentals of Data Structures Instructor: Suprakash Datta Office : LAS 3043 Course page: http://www.eecs.yorku.ca/course/2011m Also on Moodle Note: Some slides in this lecture are adopted from James
More informationPlotting run-time graphically. Plotting run-time graphically. CS241 Algorithmics - week 1 review. Prefix Averages - Algorithm #1
CS241 - week 1 review Special classes of algorithms: logarithmic: O(log n) linear: O(n) quadratic: O(n 2 ) polynomial: O(n k ), k 1 exponential: O(a n ), a > 1 Classifying algorithms is generally done
More informationSorting. Popular algorithms: Many algorithms for sorting in parallel also exist.
Sorting Popular algorithms: Selection sort* Insertion sort* Bubble sort* Quick sort* Comb-sort Shell-sort Heap sort* Merge sort* Counting-sort Radix-sort Bucket-sort Tim-sort Many algorithms for sorting
More informationComparisons. Θ(n 2 ) Θ(n) Sorting Revisited. So far we talked about two algorithms to sort an array of numbers. What is the advantage of merge sort?
So far we have studied: Comparisons Insertion Sort Merge Sort Worst case Θ(n 2 ) Θ(nlgn) Best case Θ(n) Θ(nlgn) Sorting Revisited So far we talked about two algorithms to sort an array of numbers What
More informationDivide & Conquer Design Technique
Divide & Conquer Design Technique Adnan YAZICI Dept. of Computer Engineering Middle East Technical Univ. Ankara - TURKEY 1 The Divide & Conquer strategy can be described in general terms as follows: A
More informationCSC Design and Analysis of Algorithms
CSC 8301- Design and Analysis of Algorithms Lecture 6 Divide and Conquer Algorithm Design Technique Divide-and-Conquer The most-well known algorithm design strategy: 1. Divide a problem instance into two
More informationCSC Design and Analysis of Algorithms. Lecture 6. Divide and Conquer Algorithm Design Technique. Divide-and-Conquer
CSC 8301- Design and Analysis of Algorithms Lecture 6 Divide and Conquer Algorithm Design Technique Divide-and-Conquer The most-well known algorithm design strategy: 1. Divide a problem instance into two
More informationComparisons. Heaps. Heaps. Heaps. Sorting Revisited. Heaps. So far we talked about two algorithms to sort an array of numbers
So far we have studied: Comparisons Tree is completely filled on all levels except possibly the lowest, which is filled from the left up to a point Insertion Sort Merge Sort Worst case Θ(n ) Θ(nlgn) Best
More informationCS 561, Lecture 1. Jared Saia University of New Mexico
CS 561, Lecture 1 Jared Saia University of New Mexico Quicksort Based on divide and conquer strategy Worst case is Θ(n 2 ) Expected running time is Θ(n log n) An In-place sorting algorithm Almost always
More informationElementary maths for GMT. Algorithm analysis Part II
Elementary maths for GMT Algorithm analysis Part II Algorithms, Big-Oh and Big-Omega An algorithm has a O( ) and Ω( ) running time By default, we mean the worst case running time A worst case O running
More informationCan we do faster? What is the theoretical best we can do?
Non-Comparison Based Sorting How fast can we sort? 2 Insertion-Sort O( n ) Merge-Sort, Quicksort (expected), Heapsort : ( n lg n ) Can we do faster? What is the theoretical best we can do? So far we have
More informationNext. 1. Covered basics of a simple design technique (Divideand-conquer) 2. Next, more sorting algorithms.
Next 1. Covered basics of a simple design technique (Divideand-conquer) Ch. 2 of the text. 2. Next, more sorting algorithms. Sorting Switch from design paradigms to applications. Sorting and order statistics
More informationAlgorithms Chapter 8 Sorting in Linear Time
Algorithms Chapter 8 Sorting in Linear Time Assistant Professor: Ching Chi Lin 林清池助理教授 chingchi.lin@gmail.com Department of Computer Science and Engineering National Taiwan Ocean University Outline Lower
More informationPresentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, Merge Sort & Quick Sort
Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015 Merge Sort & Quick Sort 1 Divide-and-Conquer Divide-and conquer is a general algorithm
More informationCSC Design and Analysis of Algorithms. Lecture 6. Divide and Conquer Algorithm Design Technique. Divide-and-Conquer
CSC 8301- Design and Analysis of Algorithms Lecture 6 Divide and Conuer Algorithm Design Techniue Divide-and-Conuer The most-well known algorithm design strategy: 1. Divide a problem instance into two
More informationCOMP Data Structures
COMP 2140 - Data Structures Shahin Kamali Topic 5 - Sorting University of Manitoba Based on notes by S. Durocher. COMP 2140 - Data Structures 1 / 55 Overview Review: Insertion Sort Merge Sort Quicksort
More informationChapter 4. Divide-and-Conquer. Copyright 2007 Pearson Addison-Wesley. All rights reserved.
Chapter 4 Divide-and-Conquer Copyright 2007 Pearson Addison-Wesley. All rights reserved. Divide-and-Conquer The most-well known algorithm design strategy: 2. Divide instance of problem into two or more
More informationModule 2: Classical Algorithm Design Techniques
Module 2: Classical Algorithm Design Techniques Dr. Natarajan Meghanathan Associate Professor of Computer Science Jackson State University Jackson, MS 39217 E-mail: natarajan.meghanathan@jsums.edu Module
More informationRun Times. Efficiency Issues. Run Times cont d. More on O( ) notation
Comp2711 S1 2006 Correctness Oheads 1 Efficiency Issues Comp2711 S1 2006 Correctness Oheads 2 Run Times An implementation may be correct with respect to the Specification Pre- and Post-condition, but nevertheless
More informationProperties of a heap (represented by an array A)
Chapter 6. HeapSort Sorting Problem Input: A sequence of n numbers < a1, a2,..., an > Output: A permutation (reordering) of the input sequence such that ' ' ' < a a a > 1 2... n HeapSort O(n lg n) worst
More informationData Structures and Algorithms. Roberto Sebastiani
Data Structures and Algorithms Roberto Sebastiani roberto.sebastiani@disi.unitn.it http://www.disi.unitn.it/~rseba - Week 0 - B.S. In Applied Computer Science Free University of Bozen/Bolzano academic
More informationCOT 6405 Introduction to Theory of Algorithms
COT 6405 Introduction to Theory of Algorithms Topic 10. Linear Time Sorting 10/5/2016 2 How fast can we sort? The sorting algorithms we learned so far Insertion Sort, Merge Sort, Heap Sort, and Quicksort
More informationTreewidth and graph minors
Treewidth and graph minors Lectures 9 and 10, December 29, 2011, January 5, 2012 We shall touch upon the theory of Graph Minors by Robertson and Seymour. This theory gives a very general condition under
More informationLecture 7. Transform-and-Conquer
Lecture 7 Transform-and-Conquer 6-1 Transform and Conquer This group of techniques solves a problem by a transformation to a simpler/more convenient instance of the same problem (instance simplification)
More informationQuestion 7.11 Show how heapsort processes the input:
Question 7.11 Show how heapsort processes the input: 142, 543, 123, 65, 453, 879, 572, 434, 111, 242, 811, 102. Solution. Step 1 Build the heap. 1.1 Place all the data into a complete binary tree in the
More information/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Sorting lower bound and Linear-time sorting Date: 9/19/17
601.433/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Sorting lower bound and Linear-time sorting Date: 9/19/17 5.1 Introduction You should all know a few ways of sorting in O(n log n)
More informationIntroduction to Algorithms
Introduction to Algorithms 6.046J/18.401J Lecture 6 Prof. Piotr Indyk Today: sorting Show that Θ (n lg n) is the best possible running time for a sorting algorithm. Design an algorithm that sorts in O(n)
More informationSorting. There exist sorting algorithms which have shown to be more efficient in practice.
Sorting Next to storing and retrieving data, sorting of data is one of the more common algorithmic tasks, with many different ways to perform it. Whenever we perform a web search and/or view statistics
More information1 Definition of Reduction
1 Definition of Reduction Problem A is reducible, or more technically Turing reducible, to problem B, denoted A B if there a main program M to solve problem A that lacks only a procedure to solve problem
More informationData Structures and Algorithms
Data Structures and Algorithms CS245-2015S-10 Sorting David Galles Department of Computer Science University of San Francisco 10-0: Main Memory Sorting All data elements can be stored in memory at the
More informationOther techniques for sorting exist, such as Linear Sorting which is not based on comparisons. Linear Sorting techniques include:
Sorting in Linear Time Comparison Sorts O(nlgn), Ω(nlgn) for some input The best we can do for comparison sorts is Ω(nlgn). Other techniques for sorting exist, such as Linear Sorting which is not based
More information( D. Θ n. ( ) f n ( ) D. Ο%
CSE 0 Name Test Spring 0 Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to run the code below is in: for i=n; i>=; i--) for j=; j
More informationl Find a partner to bounce ideas off of l Assignment 2 l Proofs should be very concrete l Proving big-o, must satisfy definition
Administrative Sorting Conclusions David Kauchak cs302 Spring 2013 l Find a partner to bounce ideas off of l Assignment 2 l Proofs should be very concrete l Proving big-o, must satisfy definition l When
More informationCS2223: Algorithms Sorting Algorithms, Heap Sort, Linear-time sort, Median and Order Statistics
CS2223: Algorithms Sorting Algorithms, Heap Sort, Linear-time sort, Median and Order Statistics 1 Sorting 1.1 Problem Statement You are given a sequence of n numbers < a 1, a 2,..., a n >. You need to
More informationDivide-and-Conquer. The most-well known algorithm design strategy: smaller instances. combining these solutions
Divide-and-Conquer The most-well known algorithm design strategy: 1. Divide instance of problem into two or more smaller instances 2. Solve smaller instances recursively 3. Obtain solution to original
More informationA 0 A 1... A i 1 A i,..., A min,..., A n 1 in their final positions the last n i elements After n 1 passes, the list is sorted.
CS6402 Design and Analysis of Algorithms _ Unit II 2.1 UNIT II BRUTE FORCE AND DIVIDE-AND-CONQUER 2.1 BRUTE FORCE Brute force is a straightforward approach to solving a problem, usually directly based
More informationHeapsort. Algorithms.
Heapsort Algorithms www.srijon.softallybd.com Outline Heaps Maintaining the heap property Building a heap The heapsort algorithm Priority queues 2 The purpose of this chapter In this chapter, we introduce
More informationDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMS QUESTION BANK Module 1 OBJECTIVE: Algorithms play the central role in both the science and the practice of computing. There are compelling reasons to study algorithms.
More information) $ f ( n) " %( g( n)
CSE 0 Name Test Spring 008 Last Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to compute the sum of the n elements of an integer array is: # A.
More informationThe Heap Data Structure
The Heap Data Structure Def: A heap is a nearly complete binary tree with the following two properties: Structural property: all levels are full, except possibly the last one, which is filled from left
More informationPACKING DIGRAPHS WITH DIRECTED CLOSED TRAILS
PACKING DIGRAPHS WITH DIRECTED CLOSED TRAILS PAUL BALISTER Abstract It has been shown [Balister, 2001] that if n is odd and m 1,, m t are integers with m i 3 and t i=1 m i = E(K n) then K n can be decomposed
More informationJana Kosecka. Linear Time Sorting, Median, Order Statistics. Many slides here are based on E. Demaine, D. Luebke slides
Jana Kosecka Linear Time Sorting, Median, Order Statistics Many slides here are based on E. Demaine, D. Luebke slides Insertion sort: Easy to code Fast on small inputs (less than ~50 elements) Fast on
More informationCPS 616 TRANSFORM-AND-CONQUER 7-1
CPS 616 TRANSFORM-AND-CONQUER 7-1 TRANSFORM AND CONQUER Group of techniques to solve a problem by first transforming the problem into one of: 1. a simpler/more convenient instance of the same problem (instance
More informationCSC Design and Analysis of Algorithms
CSC : Lecture 7 CSC - Design and Analysis of Algorithms Lecture 7 Transform and Conquer I Algorithm Design Technique CSC : Lecture 7 Transform and Conquer This group of techniques solves a problem by a
More informationLecture 5: Sorting Part A
Lecture 5: Sorting Part A Heapsort Running time O(n lg n), like merge sort Sorts in place (as insertion sort), only constant number of array elements are stored outside the input array at any time Combines
More information2/26/2016. Divide and Conquer. Chapter 6. The Divide and Conquer Paradigm
Divide and Conquer Chapter 6 Divide and Conquer A divide and conquer algorithm divides the problem instance into a number of subinstances (in most cases 2), recursively solves each subinsance separately,
More informationModule 6 NP-Complete Problems and Heuristics
Module 6 NP-Complete Problems and Heuristics Dr. Natarajan Meghanathan Professor of Computer Science Jackson State University Jackson, MS 39217 E-mail: natarajan.meghanathan@jsums.edu P, NP-Problems Class
More informationCS 440 Theory of Algorithms /
CS 440 Theory of Algorithms / CS 468 Algorithms in Bioinformaticsi Brute Force. Design and Analysis of Algorithms - Chapter 3 3-0 Brute Force A straightforward approach usually based on problem statement
More informationDivide & Conquer. 2. Conquer the sub-problems by solving them recursively. 1. Divide the problem into number of sub-problems
Divide & Conquer Divide & Conquer The Divide & Conquer approach breaks down the problem into multiple smaller sub-problems, solves the sub-problems recursively, then combines the solutions of the sub-problems
More informationCSC Design and Analysis of Algorithms. Lecture 7. Transform and Conquer I Algorithm Design Technique. Transform and Conquer
// CSC - Design and Analysis of Algorithms Lecture 7 Transform and Conquer I Algorithm Design Technique Transform and Conquer This group of techniques solves a problem by a transformation to a simpler/more
More informationDivide-and-Conquer. Dr. Yingwu Zhu
Divide-and-Conquer Dr. Yingwu Zhu Divide-and-Conquer The most-well known algorithm design technique: 1. Divide instance of problem into two or more smaller instances 2. Solve smaller instances independently
More informationCS473 - Algorithms I
CS473 - Algorithms I Lecture 4 The Divide-and-Conquer Design Paradigm View in slide-show mode 1 Reminder: Merge Sort Input array A sort this half sort this half Divide Conquer merge two sorted halves Combine
More informationIntroduction to Algorithms
Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 5 Prof. Erik Demaine How fast can we sort? All the sorting algorithms we have seen so far are comparison sorts: only use comparisons to determine
More informationData Structures and Algorithms
Data Structures and Algorithms CS245-2015S-08 Priority Queues Heaps David Galles Department of Computer Science University of San Francisco 08-0: Priority Queue ADT Operations Add an element / key pair
More information[ 11.2, 11.3, 11.4] Analysis of Algorithms. Complexity of Algorithms. 400 lecture note # Overview
400 lecture note #0 [.2,.3,.4] Analysis of Algorithms Complexity of Algorithms 0. Overview The complexity of an algorithm refers to the amount of time and/or space it requires to execute. The analysis
More informationCSCE 411 Design and Analysis of Algorithms
CSCE 411 Design and Analysis of Algorithms Set 4: Transform and Conquer Slides by Prof. Jennifer Welch Spring 2014 CSCE 411, Spring 2014: Set 4 1 General Idea of Transform & Conquer 1. Transform the original
More information1 (15 points) LexicoSort
CS161 Homework 2 Due: 22 April 2016, 12 noon Submit on Gradescope Handed out: 15 April 2016 Instructions: Please answer the following questions to the best of your ability. If you are asked to show your
More informationlecture notes September 2, How to sort?
.30 lecture notes September 2, 203 How to sort? Lecturer: Michel Goemans The task of sorting. Setup Suppose we have n objects that we need to sort according to some ordering. These could be integers or
More informationLower Bound on Comparison-based Sorting
Lower Bound on Comparison-based Sorting Different sorting algorithms may have different time complexity, how to know whether the running time of an algorithm is best possible? We know of several sorting
More information2. Sorting. 2.1 Introduction
2. Sorting 2.1 Introduction Given a set of n objects, it is often necessary to sort them based on some characteristic, be it size, importance, spelling, etc. It is trivial for a human to do this with a
More informationCS Divide and Conquer
CS483-07 Divide and Conquer Instructor: Fei Li Room 443 ST II Office hours: Tue. & Thur. 1:30pm - 2:30pm or by appointments lifei@cs.gmu.edu with subject: CS483 http://www.cs.gmu.edu/ lifei/teaching/cs483_fall07/
More informationHeaps, Heapsort, Priority Queues
9/8/208 Heaps, Heapsort, Priority Queues So Far Insertion Sort: O(n 2 ) worst case Linked List: O(n) search, some operations O(n 2 ) Heap: Data structure and associated algorithms, Not garbage collection
More informationwould be included in is small: to be exact. Thus with probability1, the same partition n+1 n+1 would be produced regardless of whether p is in the inp
1 Introduction 1.1 Parallel Randomized Algorihtms Using Sampling A fundamental strategy used in designing ecient algorithms is divide-and-conquer, where that input data is partitioned into several subproblems
More information2. (a) Explain when the Quick sort is preferred to merge sort and vice-versa.
Code No: RR210504 Set No. 1 1. (a) Order the following functions according to their order of growth (from the lowest to the highest). (n-2)!, 5 log (n+100) 10,2 2n, 0.001n 4 +3n 3 +1, ln 2 n, n 1/3, 3
More informationCS S-11 Sorting in Θ(nlgn) 1. Base Case: A list of length 1 or length 0 is already sorted. Recursive Case:
CS245-2015S-11 Sorting in Θ(nlgn) 1 11-0: Merge Sort Recursive Sorting Base Case: A list of length 1 or length 0 is already sorted Recursive Case: Split the list in half Recursively sort two halves Merge
More informationLecture 8: Mergesort / Quicksort Steven Skiena
Lecture 8: Mergesort / Quicksort Steven Skiena Department of Computer Science State University of New York Stony Brook, NY 11794 4400 http://www.cs.stonybrook.edu/ skiena Problem of the Day Give an efficient
More informationMA 252: Data Structures and Algorithms Lecture 9. Partha Sarathi Mandal. Dept. of Mathematics, IIT Guwahati
MA 252: Data Structures and Algorithms Lecture 9 http://www.iitg.ernet.in/psm/indexing_ma252/y12/index.html Partha Sarathi Mandal Dept. of Mathematics, IIT Guwahati More about quicksort We are lucky if
More informationThe resulting array is written as row i + 1 in our matrix:
Homework 5 Solutions Fundamental Algorithms, Fall 2004, Professor Yap Due: Thu December 9, in class SOLUTION PREPARED BY Instructor and T.A.s Ariel Cohen and Vikram Sharma INSTRUCTIONS: NOTICE: In the
More informationFINAL EXAM SOLUTIONS
COMP/MATH 3804 Design and Analysis of Algorithms I Fall 2015 FINAL EXAM SOLUTIONS Question 1 (12%). Modify Euclid s algorithm as follows. function Newclid(a,b) if a
More information5. DIVIDE AND CONQUER I
5. DIVIDE AND CONQUER I mergesort counting inversions closest pair of points randomized quicksort median and selection Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley Copyright 2013
More informationPartha Sarathi Manal
MA 515: Introduction to Algorithms & MA353 : Design and Analysis of Algorithms [3-0-0-6] Lecture 11 http://www.iitg.ernet.in/psm/indexing_ma353/y09/index.html Partha Sarathi Manal psm@iitg.ernet.in Dept.
More information( ) n 3. n 2 ( ) D. Ο
CSE 0 Name Test Summer 0 Last Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to multiply two n n matrices is: A. Θ( n) B. Θ( max( m,n, p) ) C.
More informationSelection (deterministic & randomized): finding the median in linear time
Lecture 4 Selection (deterministic & randomized): finding the median in linear time 4.1 Overview Given an unsorted array, how quickly can one find the median element? Can one do it more quickly than bysorting?
More information( ). Which of ( ) ( ) " #& ( ) " # g( n) ( ) " # f ( n) Test 1
CSE 0 Name Test Summer 006 Last Digits of Student ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to multiply two n x n matrices is: A. "( n) B. "( nlogn) # C.
More informationSorting. CMPS 2200 Fall Carola Wenk Slides courtesy of Charles Leiserson with small changes by Carola Wenk
CMPS 2200 Fall 2014 Sorting Carola Wenk Slides courtesy of Charles Leiserson with small changes by Carola Wenk 11/11/14 CMPS 2200 Intro. to Algorithms 1 How fast can we sort? All the sorting algorithms
More informationModule 6 P, NP, NP-Complete Problems and Approximation Algorithms
Module 6 P, NP, NP-Complete Problems and Approximation Algorithms Dr. Natarajan Meghanathan Associate Professor of Computer Science Jackson State University Jackson, MS 39217 E-mail: natarajan.meghanathan@jsums.edu
More informationPrinciples of Algorithm Design
Principles of Algorithm Design When you are trying to design an algorithm or a data structure, it s often hard to see how to accomplish the task. The following techniques can often be useful: 1. Experiment
More informationCSE 100: B+ TREE, 2-3 TREE, NP- COMPLETNESS
CSE 100: B+ TREE, 2-3 TREE, NP- COMPLETNESS Analyzing find in B-trees Since the B-tree is perfectly height-balanced, the worst case time cost for find is O(logN) Best case: If every internal node is completely
More informationIntroduction to Algorithms 6.046J/18.401J
Introduction to Algorithms 6.046J/18.401J Menu for Today Show that Θ (n lg n) is the best possible running time for a sorting algorithm. Design an algorithm that sorts in linear time. Hint: maybe the models
More information( ) + n. ( ) = n "1) + n. ( ) = T n 2. ( ) = 2T n 2. ( ) = T( n 2 ) +1
CSE 0 Name Test Summer 00 Last Digits of Student ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. Suppose you are sorting millions of keys that consist of three decimal
More informationCHAPTER 7 Iris Hui-Ru Jiang Fall 2008
CHAPTER 7 SORTING Iris Hui-Ru Jiang Fall 2008 2 Contents Comparison sort Bubble sort Selection sort Insertion sort Merge sort Quick sort Heap sort Introspective sort (Introsort) Readings Chapter 7 The
More informationDivide and Conquer CISC4080, Computer Algorithms CIS, Fordham Univ. Instructor: X. Zhang
Divide and Conquer CISC4080, Computer Algorithms CIS, Fordham Univ. Instructor: X. Zhang Acknowledgement The set of slides have use materials from the following resources Slides for textbook by Dr. Y.
More informationAn Optimal Algorithm for the Euclidean Bottleneck Full Steiner Tree Problem
An Optimal Algorithm for the Euclidean Bottleneck Full Steiner Tree Problem Ahmad Biniaz Anil Maheshwari Michiel Smid September 30, 2013 Abstract Let P and S be two disjoint sets of n and m points in the
More informationCS Data Structures and Algorithm Analysis
CS 483 - Data Structures and Algorithm Analysis Lecture VI: Chapter 5, part 2; Chapter 6, part 1 R. Paul Wiegand George Mason University, Department of Computer Science March 8, 2006 Outline 1 Topological
More informationChapter 8 Sorting in Linear Time
Chapter 8 Sorting in Linear Time The slides for this course are based on the course textbook: Cormen, Leiserson, Rivest, and Stein, Introduction to Algorithms, 3rd edition, The MIT Press, McGraw-Hill,
More information