To find the largest number in an array, you must look at every element. If you skip one, it might be the max.
One loop from start to end. n comparisons. This is O(n).
An array of 100 elements takes roughly twice as long as 50 elements.
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
(Finding maximum)
To find the largest number in an array, you must look at every element. If you skip one, it might be the max.
One loop from start to end. n comparisons. This is O(n).
An array of 100 elements takes roughly twice as long as 50 elements.