Question: For the following pseudo codes, find the Big-Oh notation (Show all steps) 1) Algorithm Factorial(a): Input: An integer a Output: The value of a factorial

For the following pseudo codes, find the Big-Oh notation (Show all steps)

1) Algorithm Factorial(a):

Input: An integer a

Output: The value of a factorial (a!)

Factorial(a)

factorial <-- 1

for k=1 to a do

factorial <-- factorial * k

return factorial

endAlg

2) Algorithm Power(a, b):

Input: Two integers a and b

Output: The value of a to the power b

Power(a, b)

power <-- 1

for k=1 to b do

power <-- power * a

return power

endAlg

3) Algorithm LinearSearch(A, n, q):

Input: An integer array A of size n and a query q that we wish to search the array for.

Output: The position of q in A or -1 if q is not in A

LinearSearch(A, n, q)

index <-- 0

while (index < n) and (A[index] <> q) do

index <-- index + 1

if (index = n) then

return -1

else

return index

endAlg

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!