The Gateway to Computer Science Excellence
+1 vote
586 views
What is the  ascending wise order of sorting algorithms which takes least time and least space to sort the elements?
in Programming by Active (3.7k points) | 586 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)
by Boss (10.1k points)
0
After heapsort which algorithm comes ?

 

Also tell which algorithm takes most maximum time and space
+1
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)
0

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

0
@Lav Don't you have Cormen? You can open it and see this yourself.
0
dear sir my phd teacher of my college is also confused thats why i asked
0
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
+1
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.
0
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
+2
0
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 ?
+1
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.
0

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 ?

0
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)
0
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
+1
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 :)
0
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
50,666 questions
56,170 answers
193,841 comments
94,047 users