Skip to content

update 'sorted' to 'ascending sorted' in comments #789

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 1 commit into from
May 6, 2019
Merged
Changes from all commits
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
24 changes: 12 additions & 12 deletions searches/binary_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
def binary_search(sorted_collection, item):
"""Pure implementation of binary search algorithm in Python

Be careful collection must be sorted, otherwise result will be
Be careful collection must be ascending sorted, otherwise result will be
unpredictable

:param sorted_collection: some sorted collection with comparable items
:param sorted_collection: some ascending sorted collection with comparable items
:param item: item value to search
:return: index of found item or None if item is not found

Expand Down Expand Up @@ -60,10 +60,10 @@ def binary_search(sorted_collection, item):
def binary_search_std_lib(sorted_collection, item):
"""Pure implementation of binary search algorithm in Python using stdlib

Be careful collection must be sorted, otherwise result will be
Be careful collection must be ascending sorted, otherwise result will be
unpredictable

:param sorted_collection: some sorted collection with comparable items
:param sorted_collection: some ascending sorted collection with comparable items
:param item: item value to search
:return: index of found item or None if item is not found

Expand All @@ -89,11 +89,11 @@ def binary_search_by_recursion(sorted_collection, item, left, right):

"""Pure implementation of binary search algorithm in Python by recursion

Be careful collection must be sorted, otherwise result will be
Be careful collection must be ascending sorted, otherwise result will be
unpredictable
First recursion should be started with left=0 and right=(len(sorted_collection)-1)

:param sorted_collection: some sorted collection with comparable items
:param sorted_collection: some ascending sorted collection with comparable items
:param item: item value to search
:return: index of found item or None if item is not found

Expand Down Expand Up @@ -123,11 +123,11 @@ def binary_search_by_recursion(sorted_collection, item, left, right):
return binary_search_by_recursion(sorted_collection, item, midpoint+1, right)

def __assert_sorted(collection):
"""Check if collection is sorted, if not - raises :py:class:`ValueError`
"""Check if collection is ascending sorted, if not - raises :py:class:`ValueError`

:param collection: collection
:return: True if collection is sorted
:raise: :py:class:`ValueError` if collection is not sorted
:return: True if collection is ascending sorted
:raise: :py:class:`ValueError` if collection is not ascending sorted

Examples:
>>> __assert_sorted([0, 1, 2, 4])
Expand All @@ -136,10 +136,10 @@ def __assert_sorted(collection):
>>> __assert_sorted([10, -1, 5])
Traceback (most recent call last):
...
ValueError: Collection must be sorted
ValueError: Collection must be ascending sorted
"""
if collection != sorted(collection):
raise ValueError('Collection must be sorted')
raise ValueError('Collection must be ascending sorted')
return True


Expand All @@ -150,7 +150,7 @@ def __assert_sorted(collection):
try:
__assert_sorted(collection)
except ValueError:
sys.exit('Sequence must be sorted to apply binary search')
sys.exit('Sequence must be ascending sorted to apply binary search')

target_input = raw_input('Enter a single number to be found in the list:\n')
target = int(target_input)
Expand Down