the incorrect value 99 was found in variable i (should be 30) Your Code ( with color highlights added ): for (int j = 0;
the incorrect value 99 was found in variable i (should be 30) Your Code ( with color highlights added ): for (int j = 0; j < arraydata.lenght ; j++ ){ if (arraydata[j]==targetvar){ i = j + 1; } } The Instructions: Exercise 6.1 : O(N) Loop A classic O(N) algorithm is linear search, where every item is looked at until the target is found Write a 'for' loop to search the array of integers arraydata, use the variable i and the .length property to control the loop Use an 'if' statement to find a match for the value in the variable targetvar When the loop terminates i MUST contain the number of comparisons to find the value That number must be +1 of the slot the item was found in, if the item was found in slot zero, it took one comparison to find it Do not declare i or initialize arraydata or targetvar it will be done for you. Write only a loop with an if inside and remember when the value was found in slot 3 it took 3+1 or 4 comparisons to find it
Step by Step Solution
There are 3 Steps involved in it
Step: 1
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started