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.
An algorithm is a procedure of solving a problem which is based on conducting a sequence of specified actions. In simple word, an algorithm is a set of instructions which solve a particular set of problems. It can be viewed as an elaborate algorithm.
Algorithm for Fibonacci series:
start
Fib n=1
Fib(n-1)=0
For (i=0;i<n;i++)
Fib(n+1)= Fib(n-1)+Fib(n)
print(Fib(n+1))
end
There is one for loop, so the complexity of the algorithm is O(n).
Comments
Leave a comment