Can Run Time Complexity of a comparison-based sorting algorithm be less than N logN? Last Updated : 13 Jul, 2022 Comments Improve Suggest changes Like Article Like Report Sorting algorithms are the means to sort a given set of data in an order according to the requirement of the user. They are primarily used to sort data in an increasing or decreasing manner. There are two types of sorting algorithms: Comparison-based sorting algorithmsNon-comparison-based sorting algorithms Comparison-based sorting algorithms: The elements of an array are compared to each other to sort the array. This type of algorithm checks if one element is greater than or equal to another element in the array. It does not do manipulation on a single array element. Examples of comparison-based algorithms: Merge sort (compare the elements and copy them), Quicksort (compare the elements and swap them), and Heap sort (Heapify the elements using comparison). Theorem: Every comparison-based sorting algorithm has the worst-case running time of \textbf Ω\textbf (\textbf N\textbf l\textbf o\textbf g\textbf N\textbf ) Proof: Let us assume a comparison-based sorting algorithm, and an array of length N. Consider the input array contains array elements like (1, 2, 3, 4, 5, -8, 10, . . ., N) in some jumbled order. We can order these N elements in N! different ways. Assumptions:1st element has N ways of ordering, 2nd element has (N - 1) ways of ordering, 3rd element has (N - 2) ways, and so on.So, these elements can be arranged in N! ways.Let us suppose, the number of comparisons this algorithm makes in the worst case to arrange is K, i.e., the maximum number of comparisons on the N sized input array is K. To correctly sort all the N! possible inputs algorithm exhibits distinct executions.Proof: By the Pigeonhole principle: If n items are put into m containers, with n > m, then at least one container must contain more than one item.Here, the pigeon is N! different inputs. The holes are 2K different executions.If 2^k < N! , this means the algorithm executes identically on 2 distinct inputs, and we can’t have a common execution of the sorting algorithm, which is averse to our assumption of a sorting algorithm.Since the sorting method is correct, 2K ≥ N! ≥ (N/2)N/2, Where we have used the fact that first N/2 terms of N*(N – 1)* … 2*1 are at least N/2.Taking log base 2 on both sides, K = (N/2)log2(N/2) = Ω(NlogN) Hence, every comparison-based sorting algorithm has the worst-case running time that can never be better than \textbf Ω\textbf (\textbf N\textbf l\textbf o\textbf g\textbf N\textbf ) . For more details, please refer: Design and Analysis of Algorithms. Comment More infoAdvertise with us Next Article Can Run Time Complexity of a comparison-based sorting algorithm be less than N logN? S shreelakshmijoshi1 Follow Improve Article Tags : Sorting DSA Complexity-analysis Practice Tags : Sorting Similar Reads Analysis of Algorithms Analysis of Algorithms is a fundamental aspect of computer science that involves evaluating performance of algorithms and programs. Efficiency is measured in terms of time and space.Basics on Analysis of Algorithms:Why is Analysis Important?Order of GrowthAsymptotic Analysis Worst, Average and Best 1 min read Complete Guide On Complexity Analysis - Data Structure and Algorithms Tutorial Complexity analysis is defined as a technique to characterise the time taken by an algorithm with respect to input size (independent from the machine, language and compiler). It is used for evaluating the variations of execution time on different algorithms. What is the need for Complexity Analysis? 15+ min read Why is Analysis of Algorithm important? Why is Performance of Algorithms Important ? There are many important things that should be taken care of, like user-friendliness, modularity, security, maintainability, etc. Why worry about performance? The answer to this is simple, we can have all the above things only if we have performance. So p 2 min read Types of Asymptotic Notations in Complexity Analysis of Algorithms We have discussed Asymptotic Analysis, and Worst, Average, and Best Cases of Algorithms. The main idea of asymptotic analysis is to have a measure of the efficiency of algorithms that don't depend on machine-specific constants and don't require algorithms to be implemented and time taken by programs 8 min read Worst, Average and Best Case Analysis of Algorithms In the previous post, we discussed how Asymptotic analysis overcomes the problems of the naive way of analyzing algorithms. Now let us learn about What is Worst, Average, and Best cases of an algorithm:1. Worst Case Analysis (Mostly used) In the worst-case analysis, we calculate the upper bound on t 10 min read Asymptotic Analysis Given two algorithms for a task, how do we find out which one is better? One naive way of doing this is - to implement both the algorithms and run the two programs on your computer for different inputs and see which one takes less time. There are many problems with this approach for the analysis of 3 min read How to Analyse Loops for Complexity Analysis of Algorithms We have discussed Asymptotic Analysis, Worst, Average and Best Cases and Asymptotic Notations in previous posts. In this post, an analysis of iterative programs with simple examples is discussed. The analysis of loops for the complexity analysis of algorithms involves finding the number of operation 15+ min read Sample Practice Problems on Complexity Analysis of Algorithms Prerequisite: Asymptotic Analysis, Worst, Average and Best Cases, Asymptotic Notations, Analysis of loops.Problem 1: Find the complexity of the below recurrence: { 3T(n-1), if n>0,T(n) = { 1, otherwiseSolution: Let us solve using substitution.T(n) = 3T(n-1) = 3(3T(n-2)) = 32T(n-2) = 33T(n-3) ... 14 min read Basics on Analysis of AlgorithmsWhy is Analysis of Algorithm important?Why is Performance of Algorithms Important ? There are many important things that should be taken care of, like user-friendliness, modularity, security, maintainability, etc. Why worry about performance? The answer to this is simple, we can have all the above things only if we have performance. So p 2 min read Asymptotic AnalysisGiven two algorithms for a task, how do we find out which one is better? One naive way of doing this is - to implement both the algorithms and run the two programs on your computer for different inputs and see which one takes less time. There are many problems with this approach for the analysis of 3 min read Worst, Average and Best Case Analysis of AlgorithmsIn the previous post, we discussed how Asymptotic analysis overcomes the problems of the naive way of analyzing algorithms. Now let us learn about What is Worst, Average, and Best cases of an algorithm:1. Worst Case Analysis (Mostly used) In the worst-case analysis, we calculate the upper bound on t 10 min read Types of Asymptotic Notations in Complexity Analysis of AlgorithmsWe have discussed Asymptotic Analysis, and Worst, Average, and Best Cases of Algorithms. The main idea of asymptotic analysis is to have a measure of the efficiency of algorithms that don't depend on machine-specific constants and don't require algorithms to be implemented and time taken by programs 8 min read How to Analyse Loops for Complexity Analysis of AlgorithmsWe have discussed Asymptotic Analysis, Worst, Average and Best Cases and Asymptotic Notations in previous posts. In this post, an analysis of iterative programs with simple examples is discussed. The analysis of loops for the complexity analysis of algorithms involves finding the number of operation 15+ min read How to analyse Complexity of Recurrence RelationThe analysis of the complexity of a recurrence relation involves finding the asymptotic upper bound on the running time of a recursive algorithm. This is usually done by finding a closed-form expression for the number of operations performed by the algorithm as a function of the input size, and then 7 min read Introduction to Amortized AnalysisAmortized Analysis is used for algorithms where an occasional operation is very slow, but most other operations are faster. In Amortized Analysis, we analyze a sequence of operations and guarantee a worst-case average time that is lower than the worst-case time of a particularly expensive operation. 10 min read Asymptotic NotationsBig O Notation Tutorial - A Guide to Big O AnalysisBig O notation is a powerful tool used in computer science to describe the time complexity or space complexity of algorithms. Big-O is a way to express the upper bound of an algorithmâs time or space complexity. Describes the asymptotic behavior (order of growth of time or space in terms of input si 10 min read Big O vs Theta Î vs Big Omega Ω Notations1. Big O notation (O): It defines an upper bound on order of growth of time taken by an algorithm or code with input size. Mathematically, if f(n) describes the running time of an algorithm; f(n) is O(g(n)) if there exist positive constant C and n0 such that,0 <= f(n) <= Cg(n) for all n >= 3 min read Examples of Big-O analysisPrerequisite: Analysis of Algorithms | Big-O analysis In the previous article, the analysis of the algorithm using Big O asymptotic notation is discussed. In this article, some examples are discussed to illustrate the Big O time complexity notation and also learn how to compute the time complexity o 13 min read Difference between Big O Notation and TildeIn asymptotic analysis of algorithms we often come across terms like Big O, Omega, Theta and Tilde, which describe the performance of an algorithm. Here, we will see difference between two notations: Big O and Tilde.Big O Notation (O) This notation is basically used to describe the asymptotic upper 4 min read Analysis of Algorithms | Big-Omega ⦠NotationIn the analysis of algorithms, asymptotic notations are used to evaluate the performance of an algorithm, in its best cases and worst cases. This article will discuss Big-Omega Notation represented by a Greek letter (â¦). Table of Content What is Big-Omega ⦠Notation?Definition of Big-Omega ⦠Notatio 9 min read Analysis of Algorithms | Î (Theta) NotationIn the analysis of algorithms, asymptotic notations are used to evaluate the performance of an algorithm by providing an exact order of growth. This article will discuss Big - Theta notations represented by a Greek letter (Î).Definition: Let g and f be the function from the set of natural numbers to 6 min read Like