Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Trace a linear search on the following unsorted array. Search Target = 13 To tra

ID: 3582636 • Letter: T

Question

Trace a linear search on the following unsorted array.

Search Target = 13

To trace a linear search, write the index of each element that is visited separated by a single space. For example, in this char array: [J, A, V, A], if you visited the first three indices, you would write: 0 1 2 If you visited the whole array, you would write: 0 1 2 3

Trace a linear search on the following unsorted array.

Search Target = 43

To trace a linear search, write the index of each element that is visited separated by a single space. For example, in this array: [J, A, V, A], if you visited the first three indices, you would write: 0 1 2 If you visited the whole array, you would write: 0 1 2 3

index: 0 1 2 3 4 5 6 7 8 value: 32 14 39 12 17 42 56 71 21

Explanation / Answer

#include<stdio.h>

int linear_search(int a[], int size, int search);

int main()
{
   int a[] = { 12, 19, 7, 54, 43, 65, 67, 32, 81 };
   linear_search(a, 9, 13);
}

int linear_search(int a[], int size,int search)
{
   int found   = 0;
   int i;

   printf("Search Target = %d ", search);
   printf("Index : ");
   for (i = 0; i < size; i++)
   {
       printf("%d ", i);
       if (a[i] == search)
       {
           found = 1;
           return found;
       }
   }
   return found;

}

-------------------------------------------------------------------------------

output on array: a[] = { 12, 19, 7, 54, 43, 65, 67, 32, 81 };

Search Target = 43
Index : 0 1 2 3 4

Search Target = 13
Index : 0 1 2 3 4 5 6 7 8

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote