What is an algorithm?
The AI Glossary
In our classes, we often pause to explain the ideas behind AI and the language used to describe it. These posts grew out of those conversations. They’re for anyone who would like to understand AI better, with no technical background assumed.
An algorithm is simply a set of instructions for carrying out a task. A recipe is an algorithm, as is a computer program, as is a clinical guideline. It specifies what to do with the information supplied and how to arrive at a result. Sorting a list of names, finding the shortest route between two places and calculating a risk score all involve algorithms. Most algorithms are not AI.
A recipe is a useful starting analogy, although a computer needs instructions that are more precise than “cook until it looks right.” The procedure might compare two values, repeat a calculation or choose a branch depending on an earlier result. It should also specify what happens when information is missing or an operation fails.
In machine learning, an algorithm and a model are related but different things. A learning algorithm is the procedure used to fit a model to examples. The model is the resulting set of learned relationships used to make predictions. A decision-tree learning algorithm, for example, chooses questions that separate the training examples; the fitted tree contains the questions and thresholds it selected.
Algorithms are not necessarily deterministic. Deterministic means that the same inputs and relevant system state produce the same result. Some algorithms deliberately include random choices. Conversely, many trained machine-learning models produce exactly the same prediction whenever they receive the same input. “Traditional software is deterministic; AI is not” is therefore an unreliable dividing line although it is often said.
It is also worth separating a procedure’s consistency from its suitability. An algorithm can apply an unfair rule perfectly. A learned model can reproduce an unfortunate pattern without anyone having written that pattern as an explicit instruction.
Consider a clinic’s referral queue. Sorting referrals by arrival date is an algorithm. Predicting which patients may need additional coordination involves a model. Deciding whether arrival order or predicted need should determine access is a service-design choice. Asking what the algorithm does is necessary; I find that asking why that rule was chosen, and who it affects, takes the analysis further.
Sources: MDN — Algorithm; scikit-learn — Decision Trees
Further reading from Harvard Chan: Public Health Perspectives — To Meet Future Needs, Health Care Leaders Must Look at the Data (Science) (2022).
To learn more, take a look at the AI in Health Care Certificate of Specialization from the Advanced Learning Academy at Harvard T.H. Chan School of Public Health. You can take an individual course or work toward the full certificate.
I’m a doctor, not a statistician. I teach the AI in Health Care Certificate of Specialization with Dr. Heather Mattie, a statistician and co-director of Harvard Chan’s Health Data Science master’s program. For more on data science and statistics, see Harvard Chan’s Health Data Science resources.
AI is a fast-moving field. This explanation reflects our class discussions and related material at the time of writing. Terminology, capabilities and tools may change.
For suggested additions or corrections, please email me at tpanch@hsph.harvard.edu.
Dr. Trishan Panch
Program Director, AI in Health Care
Harvard T.H. Chan School of Public Health — Advanced Learning Academy