Heap sort is "obviously" in-place, and O(n log n) time complexity.
What is meant by an "In-Place" Sort?
This is also one definition that is sometimes used. It has nothing to do with the algorithm, but more with the interface.
The underlying sort could be any sort algo, naturally. Some algos are just better suited for in-place sorting and some are better suited for non-in-place sorting (i.e. they put the sorting results in a separate space anyway, and to be in-place they''d have to copy this data to the original place).
//in-place sortarray = [2,3,1]sort(array)print array //prints [1,2,3]//not in-place sort:array = [2,3,1]array2 = sorted(array)print array //prints [2,3,1]. was not sorted in-placeprint array2 //prints [1,2,3]. the sorted array was returned
The underlying sort could be any sort algo, naturally. Some algos are just better suited for in-place sorting and some are better suited for non-in-place sorting (i.e. they put the sorting results in a separate space anyway, and to be in-place they''d have to copy this data to the original place).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement