What is an algorithm?
It’s a reasonably straightforward question isn’t it? But one that yields quite a few debates. I’ve written the following answer to ‘what is an algorithm?’ question based around the STEM computing classes with children.
First it helps I find it helps if you pretend you’re asking one of these to solve a problem; if you don’t tell them everything they get into a real mess!
An Algorithm is a precise set of instructions to solve a problem*
For me, that gets to the heart of the definition: solving a problem in a precise manner.
The problem being solved could be as simple as calculating the number of times ‘as’ appears in this sentence or as complicated as finding the quickest route for a journey across rush hour London.
What’s interesting about algorithms and not obvious from their definition is that once created, executed and observed they can often be refactored/reused to solve other problems that require the same generic process to solve.
For example, I’ve lost count of the times I’ve written a function to solve a specific problem then subsequently refined and abstracted it slightly to solve a much broader range of problems, often implemented using polymorphism. This elasticity, once you recognise it, is for me, the root of writing maintainable code. e.g. In the example above, rather than searching for a specific word, you would refine the algorithm to search for any word. This is obviously beyond the stated curriculum but a nice example of a way to illustrate a seemingly abstract part of the curriculum.
I’ve been asked about efficacy a few times as part of the definition and my view is that its not part of the definition. Efficacy is important for Computing Science but it’s not part of the definition.
* As some children are pretty young, under 7, we don’t talk about Turing machines. But I know a few people favour this addition to the definition and describe it as something that could be simulated by a Turing complete machine. Although I do wonder if we could somehow simplify and adapt this into the design and discussion of Turing machines…