And what would be the conditions that must be met during execution of the function? (Assertion)
I want to make sure that my assertion would describe what I know is true after running the ith loop.
int linearsearch(int arr[], int n, int target) {
for (int i = 0; i < n; i++) {
if (arr[i] == target) return i;
}
return -1;
}
This is just an iterative linear search function that returns the index of the target if the target is found and -1 otherwise.