Algorithms have three main characteristics:
- They are sequential.
- Algorithms are performed step by step from start to finish. Kenny’s algorithm had to first build one pair of students, then another pair, then another pair, until all the students were paired up.
- They are conditional.
- Algorithms perform certain steps based on conditions of the system. Kenny’s algorithm needs to check the grade of each student as it builds the pairs to make sure that the highest scoring student is paired with the lowest scoring student and so forth.
- They are generalizable.
- Algorithms are applicable to many different problems that are of a similar type. For example, Kenny used his sorting algorithm to pair students in each of his different classes and then, later in the day, he also used it to build a tournament bracket for the school’s chess club. These are two different applications, but the generalizable nature of the sorting algorithm allowed it to be used in both situations.
What would have been a pretty annoying task to do by hand became an easy job for the computer. This is the power of algorithms! Nearly every piece of technology in the world today uses some form of algorithms to sort, store, and access data efficiently and accurately.
Studying computer science gives you the tools you need to apply algorithmic thinking to real-world problems and quickly complete tasks and optimize processes that would have otherwise been a burden to tackle. Kenny doesn’t know it yet, but algorithms are going to help him a lot in all sorts of situations!
We saw the code of Kenny’s sorting algorithm in the last exercise. But what was it really doing? With algorithms, it is helpful to break them down to their individual steps to see how they work.
The steps of Kenny’s algorithm are shown in the diagram. Read through them and imagine how they work, then go back to the last exercise and see if you can identify what piece of code is associated with each step.
Once you feel comfortable with this algorithm, take a minute to think about other situations where the same sorting method could be useful.