Most computer programs follow sets of rules so that they can operate perfectly every day without human interference.
These rules are called Algorithms.
Before any code is written, these rules must be identified and formalised in a process referred to as ‘Algorithm Design’.
In this lesson, we will learn about:
An algorithm is a description, independent of language, of a process that achieves some task.
The idea is that you could give an algorithm, written in a text file, to any programmer and then he can build your program in whatever language – Python, C#, VB.NET, Pascal, C++, Java, etc.
It can also be thought of as a sequence of steps, independent of any programming language, that can be performed over and over again, to achieve a task, almost like a set of rules.
We follow algorithms every day without thinking.
Consider an algorithm for crossing the road:
Is this algorithm correct? Could you follow these rules every time you cross the road?
In order to design an algorithm, you need to follow some basic steps.
Let us consider our algorithm from a previous lesson of a teacher logging into an Information Management System and searching for a student.
The teacher will need to log in using a username and password.
The teacher will be given a list of matching students from which they need to select the correct one.
Once they select a student, the student’s ID will be used to display the full details.
Step 1 – Understand the problem
Make sure you fully understand the problem you have been set.
A teacher needs to log in, search by surname, pick from a list and view the correct data.
If you do not fully understand the problem, you need to go back to your Client.
Step 2 – Identify the inputs
You need to identify the type and values of the data.
These can correspond to NOUNS in a problem statement e.g. “search by SURNAME” indicates a noun input.
First is a username and password, they will be a value as words or words and numbers.
Then there is the student surname, this will be words.
Finally, there will be the student ID selected from the list.
Step 3 – Identify the processes
Are there any calculations, or is there any other computational operations going on? Are there any at all?
These usually correspond to verbs in a problem statement e.g. “SEARCH by surname” indicates a verb process.
The username and password will be used to search the database to see if there is a match.
The student name will be used to search the databases to see if there are any matches.
The selected student ID will be used to search the database to retrieve the student details.
Step 4 – Identify the data storage
There has to be a database, containing a list of usernames and passwords, and a list of students with all of their contact details as well as their student IDs.
We don’t know if this is going to be one or two databases at this time.
Step 5 – Identify the outputs
The first output will be either a confirmation or rejection of the teacher login.
The second output will be a list of students with a matching surname to the input.
The final output will be the contact details of the student selected from the list.
Step 6 – Collect your notes
Organise your data into a quad diagram.
This is simply four boxes showing the Inputs, Processes, Outputs and Data storage required by your algorithm.
Algorithms are sets of rules to follow to solve a particular problem.
They are an operational set of steps that can be followed repeatedly.
Algorithm design can be broken down into 5 distinct steps: