Question: What are the cost functions of these algorithms? Algorithm 1 input: sorted vals[n] and element e output: true if e is in vals low =
What are the cost functions of these algorithms?
Algorithm 1
input: sorted vals[n] and element e output: true if e is in vals low = 0 high = n - 1 while low <= high mid = (low + high) / 2 if vals[mid] == e return true else if e < vals[mid] high = mid - 1 else low = mid + 1 return false
Algorithm 2
input: A[n], B[n] output: dot product of A and B sum = 0 for i = 0 ... n sum = sum + A[i] * B[i] return sum
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
