Menu

(Solved) : 1 State Size Input Big Oh Example Input Algorithm Array Size K Input Size O K 2 Derive Co Q44114124 . . .

1. State the size of the input in big-Oh. For example, if theinput to an algorithm is an array of size k, then the input size isO(k).

2. Derive the cost function for the algorithm. Be sure to showyour work. You can use O(1) to denote all constants.

3. State the complexity of the algorithm in Big-Oh. Thecomplexity MUST be stated in terms of input-size.

Problem: Root of the Problem

input: integer n

output: closest integer that is the square root of n

l = 1

h = n

while l < h

r = (l + h) / 2

s = r * r

if s == n

break

if s < n

l = r

else

h = r

return s

Problem: Last Resort?

input: A[k] // 1D array of size k, k is a power of 2

output: sorted array A

B = array(k)

size = 1

while size <= k / 2

count = (k / 2) / size

for i = 0 … count

combine(A, i * size * 2, size, B)

for i = 0 … k

A[i] = B[i]

size = size * 2

return A

def combine(A, start, size, B)

h = start

i = start

j = start + size

end = start + size

while (i < end) and (j < end + size) i

f A[i] <= A[j]

B[h] = A[i]

i = i + 1

else B[h] = A[j]

j = j + 1

h = h + 1

if j < end + size

i = j

end = end + size

while i < end

B[h] = A[i]

i = i + 1

h = h + 1

Expert Answer


Answer to 1. State the size of the input in big-Oh. For example, if the input to an algorithm is an array of size k, then the inpu…

OR