Skip to content

Commit 7677c37

Browse files
weixuanhupoyea
authored andcommitted
update 'sorted' to 'ascending sorted' in comments (TheAlgorithms#789)
To avoid confusion all 'sorted' to 'ascending sorted' in comments
1 parent e22ea7e commit 7677c37

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

searches/binary_search.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
def binary_search(sorted_collection, item):
2222
"""Pure implementation of binary search algorithm in Python
2323
24-
Be careful collection must be sorted, otherwise result will be
24+
Be careful collection must be ascending sorted, otherwise result will be
2525
unpredictable
2626
27-
:param sorted_collection: some sorted collection with comparable items
27+
:param sorted_collection: some ascending sorted collection with comparable items
2828
:param item: item value to search
2929
:return: index of found item or None if item is not found
3030
@@ -60,10 +60,10 @@ def binary_search(sorted_collection, item):
6060
def binary_search_std_lib(sorted_collection, item):
6161
"""Pure implementation of binary search algorithm in Python using stdlib
6262
63-
Be careful collection must be sorted, otherwise result will be
63+
Be careful collection must be ascending sorted, otherwise result will be
6464
unpredictable
6565
66-
:param sorted_collection: some sorted collection with comparable items
66+
:param sorted_collection: some ascending sorted collection with comparable items
6767
:param item: item value to search
6868
:return: index of found item or None if item is not found
6969
@@ -89,11 +89,11 @@ def binary_search_by_recursion(sorted_collection, item, left, right):
8989

9090
"""Pure implementation of binary search algorithm in Python by recursion
9191
92-
Be careful collection must be sorted, otherwise result will be
92+
Be careful collection must be ascending sorted, otherwise result will be
9393
unpredictable
9494
First recursion should be started with left=0 and right=(len(sorted_collection)-1)
9595
96-
:param sorted_collection: some sorted collection with comparable items
96+
:param sorted_collection: some ascending sorted collection with comparable items
9797
:param item: item value to search
9898
:return: index of found item or None if item is not found
9999
@@ -123,11 +123,11 @@ def binary_search_by_recursion(sorted_collection, item, left, right):
123123
return binary_search_by_recursion(sorted_collection, item, midpoint+1, right)
124124

125125
def __assert_sorted(collection):
126-
"""Check if collection is sorted, if not - raises :py:class:`ValueError`
126+
"""Check if collection is ascending sorted, if not - raises :py:class:`ValueError`
127127
128128
:param collection: collection
129-
:return: True if collection is sorted
130-
:raise: :py:class:`ValueError` if collection is not sorted
129+
:return: True if collection is ascending sorted
130+
:raise: :py:class:`ValueError` if collection is not ascending sorted
131131
132132
Examples:
133133
>>> __assert_sorted([0, 1, 2, 4])
@@ -136,10 +136,10 @@ def __assert_sorted(collection):
136136
>>> __assert_sorted([10, -1, 5])
137137
Traceback (most recent call last):
138138
...
139-
ValueError: Collection must be sorted
139+
ValueError: Collection must be ascending sorted
140140
"""
141141
if collection != sorted(collection):
142-
raise ValueError('Collection must be sorted')
142+
raise ValueError('Collection must be ascending sorted')
143143
return True
144144

145145

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

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

0 commit comments

Comments
 (0)