Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I was wondering which sorting algorithm between bubble sort, insertion sort, merge sort, quick sort and selection sort is the worst to use to sort a list of 100 million elements if you have limited computer space and why?
Probably selection sort. It's inefficient compared to the other options, at a time complexity of Ω(n²), as opposed to bubble and insertion sort at Ω(n) and quick and merge sort at Ω(n log(n)).
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am really not able to understand how the bubble sort algorithm works. I am newbie to algorithms.
Bubble sort simply swaps two elements directly comparing them without any advanced programming technique.It works in O(n^2) time that is it will take n^2 amount of proportional time where n is number of elements.
You should have done a some amount of effort as this is available in great visualization here https://visualgo.net/bn/sorting?slide=1.
This will definitely clarify the concept.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Why does quick sort sort a given set of already sorted items and reverse sorted items with equal speed.
Why not others like heap sort, insertion sort, or selection sort?
Standard selection sort, heap sort and quick sort are not adaptive as insertion sort is.
Look at the table of sorting algorithms comparison.
For example, both the best and the worst case for selection sort has complexity O(n^2) - every cycle run always walks through predetermined piece of array.
Speed of quick sort depends on proper choice of partition elements for given data set. Sorted order may influence, if partition is silly (for example, one always gets the first element of piece), otherwise probability of the worst (quadratic) case is rather small.
If you need to sort almost sorted datasets, choose some adaptive sorting, for example, natural merge sort (or insertion sort for small datasets).
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
In the book Introduction to Algorithms (Corman), exercise 1.2-2 asks a the following question about comparing implementations of insertion sort and merge sort. For inputs of size n, insertion sort runs in 8n^2 steps while merge sort runs in 64n lg n steps; for which values of n does insertion sort beat merge sort?
Although I am interested in the answer, I am more interested in how to find the answer step by step (so that I can repeat the process to compare any two given algorithms if at all possible).
At first glance, this problem seems similar to something like finding the break even point in business-calculus, a class which I took more than 5 years ago, but I am not sure so any help would be appreciated.
Thank you
P/S If my tags are incorrect, this question is incorrectly categorized, or some other convention is being abused here please limit the chastising to a minimum, as this is my first time posting a question.
Since you are to find when insertion sort beats merge sort
8n^2<=64nlogn
n^2<=8nlogn
n<=8logn
On solving n-8logn = 0 you get
n = 43.411
So for n<=43 insertion sort works better than merge sort.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I had made the comparison in between 2 algorithms, A and B. I found that, the time complexity of these 2 algorithms is different, which are O(n^3) and O(n^4) respectively, but the space complexity of both A and B is same, which is O(n). Is that have probability?
That is possible, yes. The time complexity and the space complexity are not necessarily related to each other.
As an example, think of various sorting algorithms, such as the ones in this list - as you see, both insertion sort and heapsort have a space-complexity (column memory) of O(1), while their time complexities are different.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have an unsorted array with n*n order. How to get the largest element from each row with complexity O(n logn).
You can not possibly do this. You have an input of size O(n * n) and each element of this input is a possible answer. You can not get better than O(n * n).