An algorithm is a detailed step-by-step process that needs to be followed in order to complete a task or to solve a problem.
There are three basic building blocks that can be used when designing algorithms:
- Sequencing
- Selection
- Iteration
These building blocks help us to convert any complex problem into a well-defined solution that can be understood and implemented by others using programming. For example, how would you design an algorithm for your morning routine?
- Wake up
- Brush your teeth
- Take a bath
- Have breakfast
- Go to school
We will learn about the first building block of algorithms – sequencing.
A sequence is a list of activities that are done one after another. Sequencing refers to the specific order in which we need to perform the activities in order to get the desired output.
Designing an algorithm for How to Make a Sandwich Every day, we do many activities in a sequence. For example, think of how you would make a sandwich. If you had to write down the steps for making a sandwich, would it be like the steps given below?
If you do these steps in any other order, would the result still be a sandwich? No!
Similarly, in programming, tasks need to be done in the correct sequence to get the desired output.
In both daily tasks and coding, if we don’t put every step in the right sequence, the result will not be what we wanted. Sequencing is a foundational concept in programming, and everything we learn in the future will build on this concept.