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
748 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
- MCNP 6 - Doubts about cells
- Given partially sorted array of type x<y => first apperance of x comes before first of y, sort in average O(n)
- What is the algorithm behind math.gcd and why it is faster Euclidean algorithm?
- Purpose of last 2 while loops in the merge algorithm of merge sort sorting technique
- Dots and Boxes with apha-beta pruning
- What is the average and worst-case time complexity of my string searching algorithm?
- Building a School Schedule Generator
- TC problem 5-2:how to calculate the probability of the indicator random variable?
- LCA of a binary tree implemented in Python
- Identify the checksum algorithm
- Algorithm for finding a subset of nodes in a weighted connected graph such that the distance between any pair nodes are under a postive number?
- Creating an efficent and time-saving algorithm to find difference between greater than and lesser than combination
- Algorithm to find neighbours of point by distance with no repeats
- Asking code suggestions about data structure and algorithm
- Heap sort with multithreading
Related Questions in SORTING
- Sorting a List by its property renames all the objects in the List
- Does Sort() method in C# use recursion?
- ARM Assembly code is not executing in Vitis IDE
- Creating an efficent and time-saving algorithm to find difference between greater than and lesser than combination
- Heap sort with multithreading
- Laravel Livewire data table sorting livewire update payload
- basic MergeSort exercise
- How to import a range into a variant array in Excel VBA and sort using the sort method?
- Looker Studio | pivot chart - sorting by metric and last month
- how to create an array of multiples of 5 and display it in reverse
- matplotlib sort barh by values
- Custom Sorting Javascript with A-Z set
- Mainframe Programming Sorting, OUTFIL REMOVECC,NODETAIL
- Soft list based on another list
- SQL query : creating table with distinct values on selected columns
Related Questions in COMPARISON
- I get very different comparison results for the same texts. [sentence-transformers/all-mpnet-base-v2]
- How can I compare the similarity between multiple sets?
- Adding numeric values in one CSV to those in another CSV based on matching another value in the same row
- Problem in printing the files which are different in 2 folders
- i want to compare and obtain new data of 2 files, but the place of the content changes lines
- Java string comparison issues
- Comparing Multiple Integers in C Workaround
- difference between .equals() and ==
- How to compare two tuple list, return the highest value and the variable name from which the highest value is found?
- Conjoint analysis in R: within model comparison of two sets of regerssion coefficients (AMCEs)
- Why aren't container comparison operators allocator agnostic?
- Compare two lists elementwise with OR
- Looker Studio Scorecard Not Showing Correct Date Range Comparison Percentage
- How to facet-wrap comparative density plots in R with ggplot
- Comparison between two identical tables in Quicksight
Related Questions in BINARY-TREE
- C++: Program for Deleting a node and return its right child:
- What is the problem in my "sumAtBis" code?
- Binary Tree preorder traversal understanding
- check if object is a binary tree in prolog
- Represent a full, but not complete, binary tree with an array structure
- Perfect binary tree in order and pre order automatic indexing
- Binary Trees Changing Node vs Changing Value of Nodes
- How to create Tree Zipper using Rust?
- in Lua, how to write an iterator for a binary tree?
- A straightforward recursive level-order traversal method?
- Creating an instance of a Binary Tree (Programming Standard ML by Robert Harper)
- Debugging AVL Tree Deletion: Unbalanced Node Not on Deletion Path
- What is the maximum degree of imbalance in a red black tree ? Is it height/2?
- Wrong output when checking whether binary tree is balanced
- Why the height of segment tree is O(logn)
Related Questions in LOWER-BOUND
- c++ using std::lower_bound to find element in array by 2 parameters
- Lower and Upper bound in postgresql
- c++ lower_bound for std::map
- A question about the argument types to the comp predicate in std::lower_bound
- get lower bound iterator of search string from set. Here, strings length in set are less than search string length
- Why is CPOptimizer unable to compute a lower bound for my model?
- std::lower_bound() vs std::map::lower_bound()
- how to compare value of variable with value of all elements in vector?
- Java Generics supertypes Wildcard ? VS Object VS AbstractList
- Prove for worst case Ω(log n) for comparison based algorithm
- Lower bound from the right in a B-tree
- Questions about the upper bound of generic in java
- C++ std::set With Custom Class Returning Wrong lower_bound Value
- Why is upper bound value of gquiz1 less than the key value
- How to use the custom comp function of std::lower_bound()?
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 # Hahtags
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.