The Gateway to Computer Science Excellence
+1 vote
What is the  ascending wise order of sorting algorithms which takes least time and least space to sort the elements?
in Programming by | 820 views

1 Answer

+1 vote
i think it should be heapsort because time complexity is O(n log n) and space complexity is O(1)
After heapsort which algorithm comes ?


Also tell which algorithm takes most maximum time and space
a)if considering only time complexity then merge sort O(n log n)

 if considering space complexity then insertion sort because it is inplace algorithm and O(1)


b) insertion sort  and quick sort has worst case time complexity of O(n^2) which is think is maximum

  and quick sort incase of having ascending order or descending order elements as input forms a skew tree(a chain growing only in one direction)

so in that case spae would be O(n) which i think is maximum because all other sorts are either O(log n) or O(1)

characterize the algorithms from ascending to descending order according to time Complexity.

@Lav Don't you have Cormen? You can open it and see this yourself.
dear sir my phd teacher of my college is also confused thats why i asked
even over here some people are saying quick sort some are saying merge sort some are saying insertion sort.

The answer is confusing thats why i had asked .

I strictly follow all your rules and regulations and i do not ask here any answer which is already present on google dear sir

hence i request you to please answer my doubt of question
phd does not imply more knowledge.

As a CS graduate, you should be learning stuff on own and not relying on what others say. This question is against the site policy -- because it is not well defined -- there are many sorting algorithms and one needs to know only the asymptotic complexity at the graduate level.
yes dear sir so according to asymptotic complexity only tell which is best algorithm and which is worst algorithm with respect to Time complexity ?

(Tell among the algorithms which are covered at graduate level only but aleast tell which is best and which is worst with respect to time complexity )


Dear sir you are my guru , i respect you and thats why i am requesting you to please answer this doubtful question i will be highly oblized to you
so from the given table bubble sort is least efficient and


merge sort and heap sort are most efficient and takes least time thats the conclusion ?
No that's not the conclusion. Quick sort performs better than both many times. The answer to this question is "it depends". According to the worst case time complexity Merge sort and heap sort wins and also Merge sort is stable.

it depends

it depends on what factors please tell ?

please tell on what basis or grounds or cases the quick sort is better and performs better many times ?

This comparison is completely about constant factors. In particular, the choice is between a suboptimal choice of the pivot for Quicksort versus the copy of the entire input for Mergesort (or the complexity of the algorithm needed to avoid this copying). It turns out that the Quicksort is more efficient: there's no theory behind this, it just happens to be faster. (Referred from Quora)
i am stil not clear with the reason that why Quick sort is better and faster.

please dont copy and paste from quora that i can also do .

if you can please explain with proper reason please tell by giving example
Example is there in my previous comment. and i also read that allocation stack space is cheap. If my comments are not making sense then i'm sorry but i tried :)
Merge sort take time complexity as O(nlogn) and space complexity as O(n). I think this is sorting algo take most time in respect of the time complexity as well.
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
52,375 questions
60,615 answers
95,433 users