Computer Science, asked by rehmanislammul1794, 1 year ago

Given an unsorted array of n elements, find if the element k is present in the array or not.

Answers

Answered by sampathlam
0
after reading of array elements use this logic
Attachments:
Answered by mindfulmaisel
0

"The two most popular type of searching techniques employed with searching in arrays are Linear search and Binary Search.

Linear Search technique is used on sorted and unsorted arrays alike whereas, binary search technique requires the array to be already sorted.

Therefore, it is necessary to sort the array first. So, in the above given case, we'll use Linear Search technique.

Since, no programming language has been specified in the question, I'll answer the question with a code in C programming language.

void linear_search(int arr[],k)

{

int found=-1;

for(int i=0; i<len(arr);i++)

{

if(ar[i]==k)

{

printf(“found at %d”,i+1);

break;

}

}

if(found==-1){

printf(“Not Found”);

}

} "

Similar questions