MATLAB: Exponential and Binary Search Algorithm


Hello, So I tried to convert a cpp program that uses exponential search and binary search. I am however getting errors within the code for MATLAB, I do not understand where I have gone wrong.
I have a main file here: PasteBin Main
Here is the function for exponential search: expo search function
This is the binary search: binary search
The errors I am getting are in the binary search function at line 4, the exponential function at line 13 and the main file at line 10. The only thing I can think of is I am not passing the information across the functions correctly?
I hope what I have done doesn't hurt your eyes too badly!

Best Answer

  • Your code:
    function [ array, N, mini, target ] = binarySearch( array, N, mini, target)
    mid = ((bound + mini) / 2);
    The 2nd line fails, because "bound" is not defined here. This should appear in the error message also.