What is the time complexity for the best and worst case of the "Main" applet listed below? What does the program do?
def Main(array, n, elem): subProgram1(X,n) p = subProgram2(X,1,n,elem)
def SubProgram1(array, n): for k in range(1,n): y = X[k] i = k - 1 while i >= 0 and X[i] > y: X[i+1] = X[i] i -= 1 X[i+1] = y
def subProgram2(array, ini, n, elem): i = (ini+n)/2 if X[i] == elem: return i if ini == n: return -1 if X[i] <> subProgram2(X, i+1, n, elem) else: subProgram2(X, ini, i-1, elem)
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here