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

What is the correct answer choice for the above question? Problem 5 1 point poss

ID: 3860411 • Letter: W

Question

What is the correct answer choice for the above question?

Problem 5 1 point possible (graded) You have 2 attempts for this problem. Here is code for linear search that uses the fact that a set of elements is sorted in increasing order: def search (L, e): for i in range(len (L)) if L[ie: return True if Llie: return False return False Consider the following code, which is an alternative version of search def newsearch(L, e) size-len (L) for i in range (size): if L[size-i-1] -e: return True if L[i]

Explanation / Answer

Answer for the given Question:

Code:

#include<iostream>

using namespace std;

bool search1(int a[],int size, int e)

{

int i=0;

for(i=0;i<size;i++)

if(a[i] == e)

return true;

if(a[i] > e)

return false;

return false;

}

bool search(int a[],int size, int e)

{

int i=0;

for(i=0;i<size;i++)

if(a[size-i-1] == e)

return true;

if(a[i] < e)

return false;

return false;

}

int main()

{

int a[] ={5,8,9,5}, e1=10;

cout<<search1(a,4,e1);

cout<<search(a,4,e1);

return 1;

}

I tested the all the senarios given in the options,

The above search and newsearch will work for both L and e i.e Option A

It will work empty will return same answer and 0, 1 and 2 size.

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