Consider: return arr[0] + arr[arr.length - 1]. You read two elements. The array could have 10 items or 10 million. The function does the same amount of work.
No loops. No recursion. Just fixed operations. This is O(1).
The time does not grow with n.
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
(Array access)
Consider: return arr[0] + arr[arr.length - 1]. You read two elements. The array could have 10 items or 10 million. The function does the same amount of work.
No loops. No recursion. Just fixed operations. This is O(1).
The time does not grow with n.