Question: implement the following psuedocode into algorithms To verify that you have implemented these algorithms correctly, you are required to add additional output statements (System.out.println) This
implement the following psuedocode into algorithms
To verify that you have implemented these algorithms correctly, you are required to add additional output statements (System.out.println) This means that your main method should call the corresponding algorithm with the relevant test data.
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
C)
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
Get step-by-step solutions from verified subject matter experts
