Define what an algorithm is and outline the characteristics of a good algorithm. Write the algorithms to display the Fibonacci series and the factorial value for a given number using Pseudo code. Determine the steps involved in the process of writing and executing a program.
Take a sample number and dry run the above two algorithms. Show the outputs at the end of each iteration and the final output. Examine what Big-O notation is and explain its role in evaluating efficiencies of algorithms. Write the Python program code for the above two algorithms and critically evaluate their efficiencies using Big-O notation.
Algorithm is a set of instruction for any task to resolve or we can say we have to follow the particular set of steps to solve the problems. The facts are called as the data and the useful information is called as the knowledge for any particular issue.
Pseudo code for Fibonacci series:
start
Fn=1
F(n-1)=0
For (i=0;i<n;i++)
F(n+1)= F(n-1)+F(n)
print(F(n+1))
end
Pseudo code for Factorial:
start
scan value n
for (i=0;i<n;i++)
fact=n*n(n-1)
print fact
end
As here we are using only one for loop in both the loop, so here the complexity of the algorithm be O(N)
Comments
Leave a comment