TL;DR

Algorithms are like recipes for data. Algorithms take different forms. Some are basic and utilitarian, while others transform science or society. In a similar vein, there are many types of recipes. Some are the basics of human nutrition. Others are transformational and provide an almost spiritual experience. New creative recipes can make dining a different experience. In both cases, technology plays a huge role in driving or being utilized. In computing, the form and details of computers are essential. They constrain the amount of data or the form it takes. In cooking, the instruments and implements of preparation open possibilities. As do the means of cooking, providing endless creativity. This analogy is powerful in explaining algorithms to the uninitiated. It is also a far deeper analogy than usually expressed.

“An algorithm is like a recipe.” ― Muhammad Waseem

An Imperfect, but Useful Analogy

The analogy of an algorithm as a recipe is common but useful. As I will discuss, the parallels of thought involving recipes for food and algorithms for data are broader than one might think initially. As recipes and dishes for cooking are commonly experienced, it works to explain algorithms to a broad audience. Let’s go through the basic elements, and then go beyond the usual narrative. I’ll briefly repeat the usual pieces of the analogy, then go a step or two deeper.

The deeper elements can touch on culture. For recipes, this is obvious as food is an expression of local culture. Algorithms are an expression of scientific culture and priorities. Their importance or lack thereof says a lot about scientific culture. Food culture is intimately related to societal and ethnic influences. It finds inspiration and influence from history. Think of how Italian food is influenced by the imported tomato today. As ingredients, spices, and flavors became available, the food changed and incorporated it. Knowledge, science and cooking techniques have transformed what we eat.

Algorithms are impacted by the scientific culture. Technology has a huge influence. The computer has influenced all of science and produced new areas of science. Information technology has become a central force in all of science. At the core of all this scientific advancement is the algorithm. The algorithm is the vehicle to take the computational engine of the computer into a useful tool for science. By the same token, the culture of science is reflected. In some areas, the algorithmic advances have largely ceased. This reflects the difficulty in funding creative work that leads to many failures between breakthroughs. A drought in algorithmic progress reflects deep issues with how the culture of science is working.

“I read recipes the same way I read science fiction. I get to the end and say to myself “well, that’s not going to happen” ― Rita Rudner

An algorithm works on a computer and operates on data. The kitchen is the realm of recipes, and they operate on ingredients. In many cases, the data needs to be prepared and transformed from its original form before the algorithm operates. Recipes do the same to ingredients. Often, these transformations are key aspects of the instructions. The order of instructions matters in both cases where parts of the solution sequence are immutable. Other parts of the instructions can be changed. They can be conducted in parallel or re-ordered to good effect. This is true of food and computing. A key part of being a chef or scientist is knowing how to make these decisions.

“In algorithms, as in life, persistence usually pays off.” ― Steven S. Skiena

Manipulating data in an array must be done in a certain order. In the same vein, slicing and dicing ingredients must proceed before adding them to the cooking dish. You do have options in the details and ordering in many cases. A key aspect of both cooking and computing is knowing when steps are equivalent. What steps can be reordered and which must be executed in lock step with the recipe? The real genius of algorithms or recipes is how data/ingredients are transformed. The magic is taking something from one form and moving to another with a completely different character. Just as a recipe is a way of drawing out and mixing flavors, an algorithm can draw out the utility and use of data. Data can be understood differently through transformations achieved by the algorithms. New purposes can emerge just as new recipes flow from old standards.

“Algorithm is arguably the single most important concept in our modern world. If we want to understand our life and our future, we should make every effort to understand what an algorithm is and how algorithms are connected to their use. An algorithm is a methodical set of steps that can be used to make calculations, resolve problems, and reach decisions. An algorithm isn’t a particular calculation, but the method followed when making the calculation. For example, if you want to calculate the average between two numbers, you can use a simple algorithm. The algorithm says: ‘First step: add the two numbers together. Second step: divide the sum by two.’ When you enter the numbers 4 and 8, you get 6. When you enter 117 and 231, you get 174.” ― Yuval Noah Harari

The Role of Technology

“I guess love’s kind of like a marshmallow in a microwave on high. After it explodes it’s still a marshmallow. but, you know, now it’s a complicated marshmallow.” ― Cath Crowley, Graffiti Moon

In both cases, technology plays a big role. For algorithms, computer technology of all sorts is essential. The nature of the computer really matters in what algorithms are efficient. A serial computer is much different than a massively parallel computer. The way a computer’s memory is organized makes a huge difference. Optimal algorithms on GPUs are much different than those on a parallel computer. The relative differences in memory levels and speed matter greatly. How do we manage the cache? These changes make an algorithm efficient or easy to program. In cooking, the computer is like the oven and stoves that produce the transformation the recipe is informing. In this way, I wonder if a GPU is the microwave oven of computers. Really fast, but sort of a route to shitty food.

“My Saturday Night. My Saturday night is like a microwave burrito. Very tough to ruin something that starts out so bad to begin with.” ― Michael Chabon

Other technologies matter for algorithms. Computing languages are ways to express algorithms. C++ or Python is vastly better than assembly language. The higher-level languages make the expression of ideas far easier and open up possibilities. Before, language algorithms were extremely limited and simple. There was a hard limit to the complexity you could tolerate in programming. The related technology is compilers, which translate the high-level language into something the computer can work with. We can see parallels to how cooking works. In many ways, programming languages are like utensils and knives used by a chef. The programmer is like the one with great skills for implementing the recipe. If you are cooking, your equipment is essential for how well a dish comes off. A mandolin can produce far better potato dishes than a knife. A ricer is great for creamy, consistent potatoes. In the same way, a high-level computer language can enable complex algorithms to be implemented.

“Controlling complexity is the essence of computer programming.” — Brian Kernighan

If we look at what a chef works with, you can see how important technology is. They use knives and spatulas to assist in the preparation of data and mix the ingredients. These tools are essential extensions of the human body or augment what we don’t easily do. The ovens and stoves are essential. Programming languages take our thoughts as instructions to be executed by the computer. In a real way, the languages are an extension of our minds. It is a way of structuring thinking into actions executed over and over. These are the recipes in the cookbooks of algorithms. The commands are the tools used to prep the data that the algorithms turn into action. These are the intellectual meals we create using computers. These have transformed society just as cooking is essential to human culture.

“An algorithm must be seen to be believed.” ― Donald Knuth,

Types of Recipes and Algorithms

“This is my invariable advice to people: Learn how to cook- try new recipes, learn from your mistakes, be fearless, and above all have fun!”― Julia Child

A useful thing to explore is the types of recipes and how they map onto algorithms. Perhaps the opposite direction is more compelling. With recipes, you have the staples, grandma’s comfort food, fast food, haute cuisine, and the cutting edge of food. We have the basic steps involving making sauces and the basic elements of recipes. These are direct analogies for algorithms of sorting, hash tables, and basic data structures. We can combine algorithms to create more complex techniques and codes for general purposes. In the same way, basic elements of recipes can be combined for something unique and special. Both algorithms and recipes have immense space for creativity and adaptability. In a special moment of creative energy, you may produce something unique and wonderful from the mixture of existing knowledge. True for either algorithms or recipes.

“Once you have mastered a technique, you barely have to look at a recipe again” ― Julia Child

Some recipes change the culinary world and become staples. The creation of the Reuben Sandwich combined pastrami beef with russian dressing, rye bread, sauerkraut and cheese. The Caesar salad has become standard worldwide. If you look at the pieces of the recipe, it is clear that the combination was inspired. It was a moment of sheer genius. Today, new recipes are being created by top chefs, ready to become popular and common in the future. In the same way, algorithms are created to change the world of computing. Google’s PageRank algorithm changed how the internet works, and its ideas power social media. Today, the LLMs creating trillions of value and visions of AI are derived from the Transformer algorithm. In each case, whether recipes or algorithms combine elements of simpler common techniques in new ways. These new ideas become the foundation of the future.

“Science is magic that works.” ― Kurt Vonnegut