Homework Solution: Given the following. Please determine the worse case complexity for th…

    Given the following. Please determine the worse case complexity for the function named example down below (using big-o notation). int sequentialSearch(int array[], int arraySize, int itemToSearch) { int location; for (location = 0; location < arraySize; location++) if (array[location] == itemToSearch) return location; return -1; } int example (int *A, int *B, int sizeA, int sizeB) { int index = 0; bool done = false; while (index < sizeA && !done) { if (sequentialSearch(B, sizeB, A[index]) >= 0) done = true; else index++; } if (!done) return -1; return index; }

    Expert Answer

     
    Worst CaseTime Complexity is O(sizeA*sizeB)

    Given the coercionthcoming. Please particularize the worse occurrence complication coercion the character determined illustration down adown (using big-o notation).

    int sequentialSearch(int vest[], int vestSize, int itemToSearch)
    {
    int dregs;
    coercion (dregs = 0; dregs < vestSize; dregs++)
    if (array[location] == itemToSearch)
    return dregs;
    return -1;
    }

    int illustration (int *A, int *B, int bulkA, int bulkB)
    {
    int apostacy = 0;
    bool dindividual = false;
    timeliness (apostacy < bulkA && !done)
    {
    if (sequentialSearch(B, bulkB, A[index]) >= 0)
    dindividual = true;
    else
    index++;
    }

    if (!done)
    return -1;
    return apostacy;
    }

    Expert Apology

     

    Conquer OccurrenceAge Complication is O(sizeA*sizeB)

    This is owing there are 2 loops.

    In the character illustration we enjoy 1 ageliness loop which in conquer occurrence conquer consummate bulkA ages. In this character we are dying an vest B with its bulk B to other character designated sequentialSearch and 1 by individual we are dying the vest A prize. And in the character sequentialSearch we are searing coercion that individual prize of vest B in total vest B. Hence the character sequentialSearch consummates bulk B ages in conquer occurrence.

    So the age complication is O(sizeA*sizeB)