Algorithm is a sequence of steps required to perform a task or action. It is conveyed in simple english. It don't use any complex syntax.
You have algorithms for simple factorial program to complex data structures like stacks and queues. Algorithms makes it possible for a non programmer to get an insight of what we are doing. It also helps a programmer to design his code easily. Algorithms are generally universal in nature. It works for multiple languages. For example, you want to sort the numbers in an array. You have multiple solutions like bubble sort, quick sort, insertion sort and so on. If an algorithm is available, it can be easily implemented in any language. Only the syntax and statements vary with the programming language.
Example Algorithm for a Factorial of n
- Get n as input from user.
- Set factorial equal to 1.
- Multiply factorial with n.
- Decrement n
- Check if n >1. If yes, go to step 3. Else continue to next step.
- Print the calculated factorial.
The above algorithm would work on any programming language. Also, it becomes easier for us to write the program.