I'm learning about Big(O). Below code is an example of O(1) constant time complexity
public class DSA {
public static void main(String args[])
{
int ar[] = {1,2,3,4};
System.out.println(fun(ar));
}
static int fun(int arr[])
{
return arr[0] * arr[arr.length - 1];
}
}
But after learning O(n), I came back to this example and found that while calling length() method on my array, on the backend the length() method counts all the elements inside an array, So do we count that backend time complexity? If yes then the above example should be of O(n) but it's known as O(1). Kindly correct me if I'm wrong.