You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Awesome repo, but I came across the quicksort solution done here and I don't believe it's the canonical solution when quicksort is typically described to be an "in-place" sort. The implemented solution allocates new arrays in which values to the left and right are placed into their corresponding auxiliary arrays (lists) -- I've denoted the places that I see them in the code w/ a comment. I believe the implementation should utilize swaps w/o allocating auxiliary data structures. Lastly, the list concatenation also incurs a linear time cost as a new list/array is allocated and all elements in each sub-array must be copied over:
def_sort(self, data):
iflen(data) <2:
returndataequal= [] # extra spaceleft= [] # extra spaceright= [] # extra spacepivot_index=len(data) //2pivot_value=data[pivot_index]
# Build the left and right partitionsforitemindata:
ifitem==pivot_value:
equal.append(item)
elifitem<pivot_value:
left.append(item)
else:
right.append(item)
# Recursively apply quick_sortleft_=self._sort(left)
right_=self._sort(right)
returnleft_+equal+right_# O(n) [where n is the size of the original input]
The text was updated successfully, but these errors were encountered:
Awesome repo, but I came across the quicksort solution done here and I don't believe it's the canonical solution when quicksort is typically described to be an "in-place" sort. The implemented solution allocates new arrays in which values to the left and right are placed into their corresponding auxiliary arrays (lists) -- I've denoted the places that I see them in the code w/ a comment. I believe the implementation should utilize swaps w/o allocating auxiliary data structures. Lastly, the list concatenation also incurs a linear time cost as a new list/array is allocated and all elements in each sub-array must be copied over:
The text was updated successfully, but these errors were encountered: