I have to come up with an algorithm to search a sorted array. Here it is:(adsbygoogle = window.adsbygoogle || []).push({});

The code is Python, but I figure anyone can read it without much explination. I have to prove that this algorithm works. I don't know how to do this!! Any help would be appreciated!!Code (Text):def binarySearch(inputArray, match):

x = -1

start = 0

end = len(inputArray) - 1

while not start == end:

midPt = (start + end) / 2

if match < inputArray[midPt]:

end = midPt - 1

elif match > inputArray[midPt]:

start = midPt + 1

else:

return midPt

if inputArray[start] == match:

x = start

return x

Thanks

**Physics Forums - The Fusion of Science and Community**

# Prove an Algorithm

Have something to add?

- Similar discussions for: Prove an Algorithm

Loading...

**Physics Forums - The Fusion of Science and Community**