O(n) - Linear Time Complexity
A linear algorithm goes through the input a constant number of times.
This is often the best possible time complexity, because it is usually necessary to access each input element at least once before reporting the answer.
Let's take an example of searching for a number in an unsorted array:
Here, in the worst case, the function might have to check every element in the array, resulting in a time complexity of O(n)
The time complexity is o(n) because to find the element in a single iteration , the loop will visit every element in the array at least once.
In the image above, the X-axis represents the size of the array, and the Y-axis represents the time it takes to search for that element. As you can see, the time it takes to search an element is gradually increasing as size of the array is increasing.
This also means for array size of 8, In worst case it will have to do 8 operation to find the element.
Therefore, the time to find the element is directly proportional to the size of the array.