What is an Algorithm?
An algorithm is a sequence of steps executed to solve a problem. The steps should be precise, and the result should be obtained after executing a finite number of steps, i.e., an algorithm should halt after a finite amount of time. There can be multiple ways to solve a problem. An efficient algorithm should take less space and time.
An algorithm can be analyzed mostly on two factors:
- Time Complexity – Execution Time taken by the algorithm.
- Space Complexity – Amount of Space required by the algorithm.
When designing an algorithm, we need to consider the computer’s architecture. Computer architectures can be sequential or parallel.
Sequential Algorithm
A sequential algorithm executes the steps or instructions in sequence one after another.
Parallel Algorithm
Time/mission-critical systems need faster output. These systems use parallel algorithms. A parallel algorithm can execute several steps concurrently on different processors and combine all the individual results to produce the final output.
Algorithm Example
Algorithm to find the greater number between two numbers
START Declare Integer A Declare Integer B OUTPUT "Enter number A = " INPUT A OUTPUT "Enter number B = " INPUT B IF A > B OUTPUT "Greater Number of A and B is = " & A ELSE IF A == B OUTPUT " Both A and B numbers are Equal." ELSE OUTPUT "Greater Number of A and B is = " & B END