Question
For the following pseudo codes, find the Big-Oh notation 1) Algorithm Factorial(a): Input: An integer a Output: The value of a factorial (a!) Factorial(a) factorial
For the following pseudo codes, find the Big-Oh notation
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started