Skip to content

Commit 0e5d600

Browse files
authored
Improve comments in exponential_search.py
Updated comments for clarity and consistency in the exponential search implementation.
1 parent e940cd6 commit 0e5d600

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

‎searches/exponential_search.py‎

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#!/usr/bin/env python3
22

33
"""
4-
Pure Python implementation of exponential search algorithm
4+
Pure Python implementation of the exponential search algorithm
55
66
For more information, see the Wikipedia page:
77
https://en.wikipedia.org/wiki/Exponential_search
88
9-
For doctests run the following command:
9+
Run doctests with the following command:
1010
python3 -m doctest -v exponential_search.py
1111
12-
For manual testing run:
12+
For manual testing, run:
1313
python3 exponential_search.py
1414
"""
1515

@@ -19,10 +19,10 @@
1919
def binary_search_by_recursion(
2020
sorted_collection: list[int], item: int, left: int = 0, right: int = -1
2121
) -> int:
22-
"""Pure implementation of binary search algorithm in Python using recursion
22+
"""Pure implementation of the binary search algorithm in Python using recursion
2323
24-
Be careful: the collection must be ascending sorted otherwise, the result will be
25-
unpredictable.
24+
Be careful: the collection must be ascendingly sorted; otherwise, the result will
25+
be unpredictable.
2626
2727
:param sorted_collection: some ascending sorted collection with comparable items
2828
:param item: item value to search
@@ -63,14 +63,14 @@ def exponential_search(sorted_collection: list[int], item: int) -> int:
6363
For more information, refer to:
6464
https://en.wikipedia.org/wiki/Exponential_search
6565
66-
Be careful: the collection must be ascending sorted, otherwise the result will be
67-
unpredictable.
66+
Be careful: the collection must be ascendingly sorted; otherwise the result will
67+
be unpredictable.
6868
6969
:param sorted_collection: some ascending sorted collection with comparable items
7070
:param item: item value to search
7171
:return: index of the found item or -1 if the item is not found
7272
73-
The time complexity of this algorithm is O(log i) where i is the index of the item.
73+
The time complexity of this algorithm is O(log i), where i is the index of the item.
7474
7575
Examples:
7676
>>> exponential_search([0, 5, 7, 10, 15], 0)
@@ -81,9 +81,8 @@ def exponential_search(sorted_collection: list[int], item: int) -> int:
8181
1
8282
>>> exponential_search([0, 5, 7, 10, 15], 6)
8383
-1
84-
85-
>>> exponential_search([], 1) # Empty array edge case
86-
-1
84+
>>> exponential_search([], 1) # Empty array edge case
85+
-1
8786
"""
8887
if list(sorted_collection) != sorted(sorted_collection):
8988
raise ValueError("sorted_collection must be sorted in ascending order")

0 commit comments

Comments
 (0)