Skip to content

Interpolation search - fix endless loop bug, divide 0 bug and update description #793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 18, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
delete 'address' and add input validation
  • Loading branch information
Vincent Hu committed May 15, 2019
commit eb0e34f85445a522e074a5e09df33e960a596997
11 changes: 8 additions & 3 deletions searches/quick_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,21 @@ def _partition(data, pivot):
"""
less, equal, greater = [], [], []
for element in data:
if element.address < pivot.address:
if element < pivot:
less.append(element)
elif element.address > pivot.address:
elif element > pivot:
greater.append(element)
else:
equal.append(element)
return less, equal, greater

def quickSelect(list, k):
#k = len(list) // 2 when trying to find the median (index that value would be when list is sorted)

#invalid input
if k>=len(list) or k<0:
return None

smaller = []
larger = []
pivot = random.randint(0, len(list) - 1)
Expand All @@ -41,4 +46,4 @@ def quickSelect(list, k):
return quickSelect(smaller, k)
#must be in larger
else:
return quickSelect(larger, k - (m + count))
return quickSelect(larger, k - (m + count))