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

Part A) Find the first element in A that is not also in B. Part B) According to

ID: 3877299 • Letter: P

Question

Part A) Find the first element in A that is not also in B.

Part B) According to the copy-and-paste technique, how would you mark up line 5 of this function by the time you had determined the complexity of the entire loop?

Please provide explanation for both parts. Thank You.

04: bool found = false;

08: found = true;
09: else
10: ++pos;
11: }
12: if (!found)
13: {
14: pos = -1;
15: }
16: return pos;
17: }

According to the copy-and-paste technique, how would you mark up
line 5 of this function by the time you had determined the complexity of the entire loop?

Explanation / Answer

explanation:

01: int firstNotIn(int *A, int *B,int nA,int nB)// function that takes two list A,B and theri sizes nA,nB

02:{

03: int pos=0;//starting from first element of list A

04: bool found = false;//initially setting found flag to false

08: found = true;//if found in B then setting found flag to true...so that loop can stop in next iteration
09: else//other wise
10: ++pos;//increamenting position
11: }
12: if (!found)//if not found then returning -1
13: {
14: pos = -1;//
15: }
16: return pos;//if found then returning its position
17: }

partB:

the complexity of the entire loop is O(n*n)

loop in line 5 , runs at max upto the size of A and breaks immediately when the element is found