The crucial change in the code could be something like:
// while loop from 0 to n - 2; i initially = 0
if( arr[i + 1] != element && arr[i] != element) i += 2;
else if(arr[i] == element){ cout << "Element present at: " << i; }
else{ cout << "Element is present at: " << i + 1; return 0; }
What do you think?
The answer is no. In the worst case you have to look at every element and there are n
of them.