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

Q)Two arrays A and B each have n elements. The elements arenot necessarily sorte

ID: 3612794 • Letter: Q

Question

Q)Two arrays A and B each have n elements. The elements arenot necessarily sorted. Each array can contain repeatedelements. We say they are disjoint if they contain no elementsin common. We wish to determine whether arrays A and B aredisjoint. If they are disjoint we return null and if not wewish to know the indices where a common element exists.

           a. The following is a proposed solution

                        for i = 0 to n-1 {

                           for j = 0 to n-1 {

                                  if(A[i] == B[j] return (i,j)

                         }}

                         returnnull

Explanation / Answer

algorithm step1 :start step2: input array a and b step3: let i=0 , j=0 step4: if a[i]=b[j] then print i,j goto step 6 step5: if i