Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions arithmetic_analysis/bisection.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ def bisection(function, a, b): # finds where the function becomes 0 in [a,b] us
print("couldn't find root in [a,b]")
return
else:
mid = (start + end) / 2
mid = start + (end - start) / 2.0
while abs(start - mid) > 10**-7: # until we achieve precise equals to 10^-7
if function(mid) == 0:
return mid
elif function(mid) * function(start) < 0:
end = mid
else:
start = mid
mid = (start + end) / 2
mid = start + (end - start) / 2.0
return mid


Expand Down
2 changes: 1 addition & 1 deletion searches/binary_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def binary_search(sorted_collection, item):
right = len(sorted_collection) - 1

while left <= right:
midpoint = (left + right) // 2
midpoint = left + (right - left) // 2
current_item = sorted_collection[midpoint]
if current_item == item:
return midpoint
Expand Down