retagged by
906 views

1 Answer

Best answer
6 votes
6 votes
As far as space complexity is concerned , first we consider those algo as having less space requirement which are inplace and hence no auxilliary space is required.

So bubble sort and selection both are simple are simple iterative sorting algos , so they will consume space mainly for the input array only.

So  1  = 2

Now coming to quicksort and mergesort ,

space required for input array = O(n)

for function call stack = O(logn)  [using tail recursion optmisation we can reduce the space complexity of function call for quicksort to O(logn) and for merge sort it is always O(logn) ]

The difference hence comes in the fact that mergesort requires auxilliary array for merge operation whereas quicksort does not require any auxilliary array as it is an inplace algorithm.

Hence space complexity of quicksort < mergesort

Therefore the correct order is : 1 = 2 < 4 < 3

Hence A) should be the correct option.

For reference on tail recursion optimisation , plz refer :

http://www.geeksforgeeks.org/quicksort-tail-call-optimization-reducing-worst-case-space-log-n/
selected by

Related questions

1 votes
1 votes
1 answer
1
2 votes
2 votes
1 answer
2
1 votes
1 votes
2 answers
4
Akash Kumar Roy asked Apr 26, 2018
3,932 views
what is Space complexity of Huffman coding?