The Gateway to Computer Science Excellence

+1 vote

is it quick sort is inplace algorithm. according to me it takes o(logn) space in best case and as i know any algo takes more then 0(1) spcae count as not inplace algo then why quick sort is inplace plz explain clearly

+2 votes

Any algorithm is in place if it does not need additional auxillary space for data structure and its input is transformed by swapping with some operations.

However a small amount of extra storage space is allowed for auxiliary variables.

Quicksort operates in-place on the data to be sorted. However, quicksort requires O(log *n*) stack space pointers to keep track of the subarrays in its divide and conquer strategy. Consequently, quicksort needs O(log^{2} *n*) additional space. Although this non-constant space technically takes quicksort out of the in-place category, quicksort and other algorithms needing only O(log *n*) additional pointers are usually considered in-place algorithms.

Most selection algorithm are also in-place

u can refer : https://en.wikipedia.org/wiki/In-place_algorithm

52,315 questions

60,427 answers

201,757 comments

95,235 users