Skip to content

Commit 4dce5d1

Browse files
authored
Merge pull request #77 from MaximSmolskiy/fix_binary_search
Fix binary search
2 parents a1303e3 + 52baa3f commit 4dce5d1

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

algorithms/Searching/binary_search.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
L_SearchRange = 1; %initial search range
1515
R_SearchRange = array_length;
1616

17-
while counter <= floor(log(array_length))+1 %maximum iteration needed to find the target
17+
while counter <= floor(log2(array_length))+1 %maximum iteration needed to find the target
1818
mid = (L_SearchRange + R_SearchRange)/2;
1919

2020
if t == A(floor(mid))
@@ -31,7 +31,7 @@
3131
counter = counter+1;
3232
end
3333
end
34-
if counter > floor(log(array_length))+1
34+
if counter > floor(log2(array_length))+1
3535
disp('target is not found in aray')
3636
end
3737
end

0 commit comments

Comments
 (0)