Given the maximum element M of array with n elements [1,...,n], how the lower bound Ω(nlogn) of time complexity of every comparison based sorting algorithm is affected? I must highlight that the maximum element M of the array is given.
Lower bound Ω(nlogn) of time complexity of every comparison based sorting algorithm given M maximum
746 Views Asked by user3133007 At
2
There are 2 best solutions below
1
Andrey Mishchenko
On
If M is really a bound on the absolute values of the elements of the array, and the elements are integers, you can sort the array in O(n + M) time, by keeping a separate array int occurrences[2M + 1]; initialized to 0, scanning your original array and counting the number of occurrences of each element, and writing the output array using occurrences.
If the elements are floats (formally, real numbers), having a bound on their magnitudes has no effect.
If the elements are integral and can be negative (formally, integers of arbitrarily large magnitude), then having an upper bound on the magnitudes has no effect.
Edit: had O(n) in first paragraph, should be O(n + M).
Related Questions in ALGORITHM
- Two different numbers in an array which their sum equals to a given value
- Given two arrays of positive numbers, re-arrange them to form a resulting array, resulting array contains the elements in the same given sequence
- Time complexity of the algorithm?
- Find a MST in O(V+E) Time in a Graph
- Why k and l for LSH used for approximate nearest neighbours?
- How to count the number of ways of choosing of k equal substrings from a List L(the list of All Substrings)
- Issues with reversing the linkedlist
- Finding first non-repeating number in integer array
- Finding average of an array
- How to check for duplicates with less time in a list over 9000 elements by python
- How to pick a number based on probability?
- Insertion Sort help in javascript -- Khan Academy
- Developing a Checkers (Draughts) engine, how to begin?
- Can Bellman-Ford algorithm be used to find shorthest path on a graph with only positive edges?
- What is the function for the KMP Failure Algorithm?
Related Questions in SORTING
- How to sort a multi-dimensional array by the second array in descending order?
- Ignore #VALUE! error in SORT function
- What is the code of the sorted function?
- Pull out first occurrences from array
- how to keep 10 biggest integer while reading a list in java?
- IQueryable<T> OrderBy<T> Extension Fails with Foreign Key Property
- Anagram test using C++ having compile time error
- How to sort a nested dictionary by the a nested value?
- sort through text file numerically by numbers in column
- Python elegant way to sort numerically named directories
- sorting all data on multiple pages by clicking on its header
- Sort oberservableArray by multiple parameters
- 2D array, sort rows by sum
- sorting RDD elements
- Less beautifier - format code
Related Questions in COMPARISON
- Cell comparison and row inserts
- How to speed up string comparisons in an array with a for loop?
- Count number of ones in a array of characters
- why the following code gives the first mobile no. irrespective of name
- Comparing two decimals
- Groovy comparison chaining
- Numpy matrix row comparison
- What is faster: equal check or sign check
- In JavaScript, is there any difference between typeof x == 'y' and typeof x === 'y'?
- Using comparable to compare different variables
- count how many times characters from a range occur in a string
- MySQL Comparison Query
- Dynamically comparing two tables from two different databases and serves in SQL Server Management Studio
- Compare two DATETIME fields from multidimensional array and return a value or index
- Bash string comparison
Related Questions in BINARY-TREE
- How to Compute Space Complexity for Printing All paths which Sum to a Given Value in Binary Tree
- Recursively divide a list that each iteration divides into two parts to get the closest sum overall
- Function that return average depth of a binary search tree
- Print a Binary Search Tree with Correct Formatting
- Recursive Tree Walk with ES6 Promise
- Making a very basic binary tree in Scala
- maximum sum of value from root to leaf in a binary tree using stack
- How to Compute Space Complexity for Binary SubTree Finding
- Scala: How to compute the sum of all elements in the leaves of a Binary Tree?
- Pass a value by reference in a function to find level of node in a binary tree
- How to implement remove() method in binary search tree iterator
- How to copy an object in Scala?
- Complex conditional filter design
- Recursively count children nodes in binary tree
- Updating value of node in Scala?
Related Questions in LOWER-BOUND
- Time complexity analysis for finding the maximum element
- Algorithms, upper/lower bounds, and best/worst case
- R upper and lower bounds for a regression function
- How to find a lower bound in a sorted vector
- How can I prove a lower bound that is \Omega{(n (logn)^k)} ? [k>1]
- The complexity of verifying solutions to NP-hard optimization problems?
- Why lambda function doesn't work in std::lower_bound while using references in key type?
- Asymptotic lower bounding does not work. Why?
- Can't understand lower bound function with comparator
- Regarding complexity (if comparison based sorting algorithm used)
- Lower bound Ω(nlogn) of time complexity of every comparison based sorting algorithm given M maximum
- Can't Understand 1 Line of Code in C++ STL Source: Lower_Bound/Upper_Bound
- c++ lower_bound for std::map
- Lower and Upper bound in postgresql
- Substitute for illegal lower bounds on a generic Java method?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
It is not affected.
Note that there are
n!possible permutation, and each compare OP has 2 possible outcomes - 'left is higher' or 'right is higher'.For any comparisons based algorithm, each 'decision' is made according to the outcome of one comparison.
Thus, in order to successfully determine the correct order of any permutation, you are going to need (at worst case) log2(n!) comparisons.
However, it is well known that log2(n!) is in Theta(nlogn) - and you got yourself back to a lower bound of Omega(nlogn), regardless of the range at hand.
Note that other methods that do not use (only) comparisons exist to sort integers more efficiently.