# I need help with this problem for C++ If a linear search function is searching for a value that is stored in the last element of a 10,000-element array, how many comparisons will the search function have to make to locate the value?

Question
30 views

I need help with this problem for C++

If a linear search function is searching for a value that is stored in the last element of a 10,000-element array, how many comparisons will the search function have to make to locate the value?

check_circle

Step 1

Often called sequential search is linear search. Linear search is a method within an array to check for a value. It sequentially searches for the target element one by one of the array until a match is found or all the elements of that array have been scanned.

Consider a 1-D array of 4 elements given below:

Step 2

Let C be the program counter pointing to the first index of array(initially value of C will be zero) and we want to search the given element G  in above array. Then number of comparisons to be made to search this element using linear search method will be:

1st comparison:

In first comparison, the given element G(i.e. 9) will be compared with element present at location pointed by counter variable C ( value of C is 0 so it will be pointing to the element at index 0 of array i.e. 4). Here both elements didn’t match hence the value of counter C will by incremented by 1.

Step 3

2nd comparison:

In this comparison, the given element G(i.e. 9) will be compared with element present at location pointed by counter variable C (value of C is 1 so it wi...

### Want to see the full answer?

See Solution

#### Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

### Programing Language 