Once a problem has been decomposed into smaller tasks, it is useful to try and identify common themes or patterns that might exist within our program or with other programs.
This helps the programmer to save time reinventing the wheel when a solution to a given problem may already exist.
In this lesson, we’ll learn about:
A pattern is something that repeatedly occurs in many different programming problems.
Patterns exist everywhere. If you were to look at how your day is organised from school to college, you would see that it follows a pattern:
This pattern holds true for each day of the week for most students in most schools and colleges.
This pattern can then be applied to any systems that track and monitor student data, including attendance, punctuality and recording homework marks.
This is because most schools and colleges follow the same pattern.
This means that one program solution can be used by many different educational organisations.
Recognising patterns – things that are common within or between problems or programs – is one of the key areas of computational thinking.
Once you identify patterns in your problem, you might find that you need to use the same pattern again and again within your problem.
For example, you might want to display a graph of student attendance. This may be needed by:
This would have the same graph pattern being used twice within the program.
Once you identify a common pattern, there is more than likely an existing solution to the problem.
For example, you might want to search for a student in a school’s Information Management System.
To do this, you would need to use a searching algorithm, like a binary or linear search.
Note: We will look at searching algorithms later on in the course.
Also, looking at the graph drawing problem from the previous section, Python contains a module called Matplotlib.
Matplotlib is a low-level graph plotting library that serves as a simple way of drawing and visualising graphical data. It is open-source and can be used freely by anyone.
This could be used as a solution for drawing graphs of student attendance.
Note: Matplotlib is one of the modules you are required to know for Paper 1 and the Employer Set Project.
Once you have identified a pattern, you can speculate whether it can be reused in your existing program or used in another program.
You can also examine the pattern to identify any software or hardware components you might need.
For example, you identify that you need a login system for a program as:
Based on this, you can predict you will need a user interface, a database to store usernames & passwords, some means of connecting the interface to the database, and some form of loop if the user gets their username or password wrong.
Patterns are things that are the same within a problem and between problems.
Identifying patterns means that there is probably an existing solution already out there.
Patterns can be repeated within a problem.
Patterns can be repeated between problems.
If a pattern is identified, then it is possible to predict what hardware and software components may be needed to solve that problem.