Answer in brief
An algorithm helps us plan a solution step by step before writing a program. It has several advantages and some limitations.
Advantages of algorithms
- Easy to understand: The solution is written as simple, ordered steps. A student can follow one step at a time.
- Helps before coding: We can decide the inputs, calculations and output before writing C statements. This reduces confusion while coding.
- Independent of a programming language: The same solution can be implemented in C, Python or another language. The syntax changes, but the main steps can remain the same.
- Helps find mistakes: We can follow the steps with sample values and check the result. Missing steps and incorrect conditions can be found before coding.
- Makes coding easier: Once the steps are clear, each step can be converted into suitable program statements.
Limitations of algorithms
- Takes time to prepare: A detailed solution needs careful planning, especially for a large problem.
- Can become lengthy: A large problem may need many steps. A long description can become difficult to follow.
- Has no single writing format: Different people may describe the same steps differently. The wording must still be clear.
- Does not show paths visually: Choices and repeated steps may be easier to see in a flowchart.
- Cannot be executed directly: An algorithm written in ordinary language must be converted into a program before the computer can run that program.
Simple example
To add two numbers: read the two values, add them and display the sum. For inputs 8 and 5, the result is 13. These steps can be understood before writing any C code. They can also be used to write a program in another language. The algorithm is useful for planning, but the computer still needs an implementation to execute.
READ a, b
sum ← a + b
OUTPUT sum
Key points
- Algorithms support reasoning before implementation.
- Choose enough detail that another person can follow the steps.