Skip to content

Commit df6c5dc

Browse files
committed
adjust quicksort comments, add todo for quickselect
1 parent 2714822 commit df6c5dc

2 files changed

Lines changed: 37 additions & 2 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
TODO
3+
quickselect algorithm
4+
find k-th smallest item in an unordered list
5+
6+
Works by separating smaller items onto one side of the pivot,
7+
not caring about the particular order but about the number of smaller items on that side.
8+
For example, with k of 5,
9+
the 5th smallest item will have 4 items smaller than it partitioned to its left.
10+
11+
https://stackoverflow.com/questions/10846482/quickselect-algorithm-understanding
12+
13+
to read
14+
http://www.cs.yale.edu/homes/aspnes/pinewiki/QuickSelect.html
15+
https://www.techiedelight.com/quickselect-algorithm/
16+
17+
18+
19+
https://www.geeksforgeeks.org/quickselect-algorithm/
20+
https://www.geeksforgeeks.org/quick-sort/
21+
22+
https://en.wikipedia.org/wiki/Quickselect
23+
https://en.wikipedia.org/wiki/Quicksort
24+
25+
26+
27+
in theory, quick sort partition method should be the same for quick select
28+
can they share a method?
29+
30+
"""
31+
32+
33+
def quick_select():
34+
pass

‎academic/examples/sort/quick.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def _quick(cls, lst, left, right):
166166
logging.debug('left: {left}, right: {right}'.format(left=left, right=right))
167167

168168
pivot_index = (left + right) // 2
169-
# possibly should/could be this?
169+
# Could be this to prevent integer overflow:
170170
# pivot_index = left + (right-left) // 2
171171

172172
logging.debug('pivot index: {ind}'.format(ind=pivot_index))
@@ -213,7 +213,8 @@ def _quick(cls, lst, left, right):
213213
)
214214
)
215215

216-
# may be needed for larger lists:
216+
# May need iterative approach for larger lists due to recursion limit
217+
# Recursion limit can be increased but not ideal for stack size/speed:
217218
# sys.setrecursionlimit(sys.getrecursionlimit() * 10)
218219

219220
cls._quick(lst, left_init, right)

0 commit comments

Comments
 (0)