I had gone through many articles over internet to find minimum number in an array. According to article they iterate an array n number of times but purpose can be achieve n/2 + 1 iteration
Here is my code
for index in range(0, int(len(myArray)/2)+1):
if minNum > myArray[index]:
minNum = myArray[index]
lastElement = - index - 1
if minNum > myArray[lastElement]:
minNum = myArray[lastElement]
Article code
for element in myArray:
if minNum > element:
minNum = element
Update my code to
for index in range(0, int(len(myArray)/2)+1):
if minNum > myArray[index]:
minNum = myArray[index]
if minNum > myArray[- index - 1]:
minNum = myArray[- index - 1]
Is there is any reason why they used n iteration