How to write an algorithm – Step 2

Step 2 – Find loops from the problem statement

After you are able to find the data, process and conditions in the problem statement you should look for indications where you can see some kind of repetitive process taking place. These repetitive processes are called loops in technical languages. What you need to remember is that loops are a combination of two things

  1. Process
  2. Condition

Inside a loop some process takes place. After every cycle the condition is checked. If the condition says that the process should continue then the loop continues. If the condition says that the process should end then the loop ends.

There are mainly two kinds of loops which you will find in your problem statements

  1. Counting loops – These loops increment or decrement some number and run till that number falls in a given range
  2. Conditional loops – These loops check for some condition. If that condition is true then the loop continues to run. If it is false then the loop ends

Let’s take an example

Read this problem statement and find out the data, process, conditions and loops from it

Rosy was given a file with marks of 10 students in a class. Each student appeared for 5 exams and scored marks. Rosy has to write an algorithm to read the marks of all these students from the data file, calculate the average marks, award the grade to each student and finally enter the average marks and final grade in the data file. If the student’s average is below 75 then he / she will be given a D grade, if the average is between 75 and 80 then he / she will be given a C grade, if the average is between 80 (including 80) and 85 then he / she will be given a B grade and if the average is above 85 (excluding 85) then he / she will be given an A grade.

This problem statement is a little bit different from the problem statement which we discussed in the previous tutorial. Here the additional requirement that is being asked is to read and write data from and to a data file. Now your goal is to find out about the data, process, conditions and loops from this statement.

Data

  1. Marks of 5 subjects are data. You will need variables to remember these marks
  2. The average you will calculate from these marks is also data. You will need a variable to store this also

Process

  1. Reading student marks from data file and loading marks into variables
  2. Calculating the average of these marks and storing it in some variable
  3. Checking in which range the average falls and awarding respective grade
  4. Writing the average marks and grade back into the data file

Conditions

 

In this problem statement there are following conditions

  1. Are the average marks below 75
  2. Are the average marks between 75 and 80
  3. Are the average marks between 80 (including 80) and 85
  4. Are the average marks above 85 (excluding 85)

Loops

 

The problem statement says that the algorithm will calculate the average marks for each student out of the list of 10 students in the data file. This clearly means that the process of reading the marks from the file, calculating the average, awarding grades and writing the average marks and grade back to the data file has to be repeated for all the 10 students. Where ever there is repetition there is a loop involved. In this case the algorithm will have a loop with counts from 1 till 10 and runs for each student in the list.

Quick Links

E-Magazines

@

Total Followers
Study Group Created
Study Group Joined
Following Teacher
Following Organization
Blog Articles Added
Questions Asked
Questions Answered
Jobs Posted
Total Members in Group
Questions asked by members
Tasks added in this Group

Please wait..

Ok

Login to Open ESchool OR Create your account    Login   SignUp