1,597 views
1 votes
1 votes
You are asked to sort 15 randomly generated numbers. One should prefer—

(a) Bubble sort (b) Quick sort (c) Merge sort (d) Heap sort

I think the answer should be c or d

crct me???

3 Answers

4 votes
4 votes
Answer is Quick Sort. (That is why it's name is Quick I guess :D )
The worst case time complexity is O(n square) but worst case is very less likely to happen.
So in most of the cases it is going to take O(nlogn)..
Now mergesort also takes O(nlogn).... but  the actual time taken for quicksort is less than merge & heapsort. ( The constant for quicksort is less than mergesort).

 In a program, I took 5 lakh random elements in the range 0-100   , it took more time than mergesort.
But I modified it & took 5 lakh elements in the range 0-5lakh .. i.e randomness was more & less repeated elements.
It took almost equal or less than mergesort.

Prefer bubble or insertion sort only when they are nearly sorted. (Do not prefer quicksort, quicksort will take huge time, worst case happens in quicksort when they are already or reversely sorted)
edited by
1 votes
1 votes
I think answer should be Quick Sort or Bubble sort as number of elements to be sorted are only15..better use Quick Sort or bubble sort as there constant factor is less compared to Merge Sort and Heapsort. For sorting large number of elements Complexity becomes relevant but for small number of elements..look for sorting that has small constant value.
0 votes
0 votes
I think we should apply any of the sorting algorithm as it have only 15 elements and it can be done in O(1) time.

So for constant length input the sorting algorithm  does not matter.

Related questions

0 votes
0 votes
0 answers
1
Rahul Ranjan 1 asked Jun 15, 2018
652 views
You are asked to sort 15 randomly generated numbers. One should prefer - 1. Bubble Sort2. Quick Sort3. Merge Sort4. Heap Sort Please explain why others 3 sorting algorith...
1 votes
1 votes
1 answer
2
kumar.dilip asked Jan 19, 2019
664 views
The average no. of comparisons performed by the merge sort algorithm, in merging 2 sorted lists of length 2 is___________.Ans: $\frac{8}{3}$
0 votes
0 votes
1 answer
3
Ramayya asked Jan 7
176 views
Worst case time complexity of heap sort for n elementsO(nlogn)O(logn)O^2O(n)