in linear search video…
there is a condition like
if(i==n)
{
cout<<“Not found”;
}
what is the key we are searching is in last of array or last element in array ???
Last one key in array
Hey @ManasxCOdE
The array has n elements from indices 0 to n-1. To do linear search, we iterate from 0th element to (n-1)th element,if the element is found between i = 0 and n-1, the for loop would break there itself and after exiting the for loop, the value of i will be the index where it’s found. But if the for loop ends & i is n. this means that element was not found from 0 to n-1 and loop finishes and i reaches n, which means element has not been found, so we print “not found”.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.