From 52baa3f2488e5e48b4e3a55eeacde633c3c5923d Mon Sep 17 00:00:00 2001 From: Smolskiy Maxim Date: Tue, 27 Jul 2021 20:55:31 +0300 Subject: [PATCH] Fix binary search --- algorithms/Searching/binary_search.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/algorithms/Searching/binary_search.m b/algorithms/Searching/binary_search.m index d2e6514..440a979 100644 --- a/algorithms/Searching/binary_search.m +++ b/algorithms/Searching/binary_search.m @@ -14,7 +14,7 @@ L_SearchRange = 1; %initial search range R_SearchRange = array_length; -while counter <= floor(log(array_length))+1 %maximum iteration needed to find the target +while counter <= floor(log2(array_length))+1 %maximum iteration needed to find the target mid = (L_SearchRange + R_SearchRange)/2; if t == A(floor(mid)) @@ -31,7 +31,7 @@ counter = counter+1; end end -if counter > floor(log(array_length))+1 +if counter > floor(log2(array_length))+1 disp('target is not found in aray') end end