Algorithms To Live By
by Brian Christian & Tom Griffiths

  • Behaviour
  • Ashto = 7/10
  • Jonesy = 5/10
Algorithms To Live By

Why Should You Read Algorithms To Live By

In Algorithms To Live By, Christian and Griffiths explore how we can apply the concept of an algorithm to improve our everyday lives. The particular set of problems that people face is a direct result of our lives being carried out in unlimited space and time. What degree of mess should we embrace? At what point is pedantic ordering excessive? What balance between new and favoured experiences make for the most fulfilling life? These questions might sound very human – only they’re not. For more than 50 years, computer scientists have been solving and grappling with all these everyday dilemmas. 

How should a processor allocate the focus to perform every task with minimum energy expenditure in the shortest possible time When should it switch between different tasks? And how many tasks should it take on at once? Should it collect more data or take action based on the data it already has? Seizing the day may seem like an overwhelming challenge for humans yet computers are seizing every millisecond. 

Algorithms aren’t limited to the world of computers. Every time you cook a meal by following a recipe – that’s an algorithm. When you stack up a bunch of kindling, light some paper on fire, then add larger blocks to make a big bonfire – that’s an algorithm. Algorithms have been part of human history since the Stone age. There’s a lot we can learn from mathematics, and they can teach us how we should run lives by algorithms. 

Ultimately, a lot of the problems we face every day are difficult. The mistakes we make in the decision-making process are less to do with the built-in flaws with our brain, but more to do with the intrinsic difficulties of the problem. By thinking algorithmically about the world, learning about the fundamental structures of the problems, and understanding the properties of their solutions, we can make better choices. 

 

  • Optimal Stopping 

When should you turn into an empty car space vs keep looking for a better spot? When should you decide to buy a house or keep looking for a better one? Should you go to your favourite Mexican restaurant or try the new Japanese restaurant that just opened down the road? Should you eat with your best friend or invite the new office colleague? Should you watch an old favourite movie or try out a new release? 

In an environment like this, it’s hard to slow down and make rational decisions; you may end up making rushed decisions. For example, if our goal is getting ‘the best apartment available’, we probably can’t just pick the first one we see. We need to reduce two seemingly contradictory goals: ‘the one that got away’ and ‘leave no stone unturned’. Obviously, the more you look and the more stones you turn over, you may overlook the perfect one during the search. What if there’s an amazing property just around the corner, but you’ve already committed? 

The more data you gather, the better your decision making will become; but that also increases the chance of missing a good option. So the question is: How do you have enough information to make an informed decision based on your research? It’s a cruel paradox. 

Example: 

In a car, you’re generally moving forward toward your destination. As you approach your destination, you start contemplating when should you settle for a vacant park. Or is it better if you keep going and hope for a spot nearer to the entrance? There are many variables in picking a parking spot – how close it is to the entrance, how far you have to walk, the cost per hour and splitting the bills, the extra fuel and time wasted looking around for one. 

PROBLEM: as you drive along the street towards your destination, every time you see an empty spot, you need to make a decision: should you take this spot or keep going and try to get one a little closer to your destination? 

ASSUMPTION: You’re on an infinitely long straight road, and your goal is to minimise the distance you have to walk to get to your destination after you park. Which empty spaces should you ignore, and when should you stop and take the next available spot?

ANSWER: For the first 37% of the parking search, you should be gathering data on how full the car park is. Once you have some intel, you then make your decision accordingly. If the car park is 80% full, you should drive until you’re 5 spots away from the door, then take the next available spot. If it’s 90% full, you should go to 8 spaces away and take the next available. If it’s 98% full, you should accept a space that is 35 spaces away from the door. This is the ‘look then leap’ solution – you look for 37% of the journey, then leap based on how full the car park is and how likely you are to find a good spot closer to the door. 

The name of this type of problem is an ‘optimal stopping’ problem – the problem isn’t which one to PICK, but how many options to CONSIDER before picking. The problem was first published in 1960, posed as a problem for recreational mathematicians to solve in Martin Gardner’s column in Scientific American. Imagine you’re interviewing a set of applicants for a position as a secretary. Your goal is to maximise the chance of hiring the single best applicant in the pool. You have no idea how to assign objective scores, but you can rank which ones you prefer over the others. Indeed, you’ve still going to be wrong the majority of the time. But this ‘optimal stopping’ algorithm means that while you’re less likely to find the needle, it is your best defence against the haystack. 

 

  • Explore/Exploit 

It’s Friday night, and your stomach is rumbling. Do you go to the trusty Italian restaurant that you know and love? Or do you go to that new Thai place that just opened up last week? Do you take your best friend? Or do you reach out to a new acquaintance to try to get to know them better? Or maybe… you stay home instead. But do you cook your go-to signature dish? Or do you search the internet for a new recipe? Or should you order UberEats? Do you get your usual, or do you check for the weekly specials? Once dinner is made, do you watch a movie or read a book? Suddenly, your relaxing Friday night doesn’t seem so relaxing anymore. 

Every day we are constantly forced to make decisions between options that differ in a particular dimension. Do we try something NEW, or stick with our FAVOURITE ones? We intuitively know that life is a balance between novelty and tradition; between the latest and the greatest; between taking a risk and savouring what we love. If you want to expand your horizons, you need to find new things to learn. But what is the right balance? What is the optimal mix between new and old? Thankfully, computer scientists have been working on finding this golden ratio for more than fifty years, called theexplore/exploit’ trade-off.

In English, the words ‘explore’ and ‘exploit’ carry opposite connotations. But to a computer scientist, these words have much more specific and neutral meanings. Simply put, exploration is GATHERING information, while exploitation is USING the information you have to get a known good result. Intuitively, avoiding exploration isn’t a good way to live your life, and not making the most of a good situation won’t maximise your life either. Exploration is vital to find new things you love, and although it’s risky, it can be rewarding when you find something new to exploit in the future. 

Multi-Armed Bandit problem 

Scientists refer to this problem as a version of the ‘multi-armed bandit’ problem. It’s like poker machines at the casino – you pull the arm and hope to get lucky. The multi-arm bandit refers to a row of poker machines, so you need to try them out to see which one pays out the most before you know which one you can use. Imagine testing both machines. You’ve pulled 15 times for 9 wins and 6 losses (60% strike rate) with the first machine, and you’ve pulled twice for 1 win and 1 loss (50% strike rate) with the other. Which one should you pull next? 

With a small sample size, it’s hard to measure the REAL odds accurately. You probably need to keep testing both out to find the long term average and be more certain of the odds. If you want to maximise your payout, you need a mix of both pulling arms on different machines (exploring) and then favouring the ones with the best odds (exploiting). 

Seize The Interval 

To find the optimal explore/exploit balance, there is one crucial variable: the time you plan on staying in the casino. If you’re only playing for a while, it’s better to play it safe and pull the arm with more certainty. If you’re going to settle in for a while, then it’s better to pull the one which you know less about, as you may find it more beneficial for the long run. 

The saying goes: ‘Start learning a new language or an instrument, make small talk with a stranger, because life is long, and who knows what may blossom over many years.’ When we try to balance our favourite experiences with new ones, nothing matters as much as the INTERVAL over which we plan to enjoy them. It’s not just about seizing the day but also seizing the interval. 

For example, Adam moved out of home, about 45 mins away from his parents. And in the first month, he tried a whole bunch of new restaurants. Recently, he moved back with the parents; and before doing so, he went to his favourite restaurant four times within a month, knowing he might never have it again. It’s normal for us to explore in the beginning, then exploit as our interval draws to a close. The value of exploring goes DOWN over time while the value of exploiting goes UP. The interval dictates the strategy, and the strategy can also infer the interval, which is prevalent in Hollywood. Movies with a large fanbase would opt for sequels as there’s a guaranteed target market. Making a new movie takes more risks, so movie studios are exploiting and less exploring to play it safe. 

 

Scheduling 

SET UP

It’s Monday morning, and you have a blank schedule with a long list of tasks that need to be actioned. But you can only start some tasks after you finish the others. Like how you can’t stack the dishwasher with dirty dishes before you unstack the clean ones. Some may have sharp deadlines, and others more flexible. So what do you do? When? In what order?

Though we manage to do it, we’re not particularly good at it. It’s no wonder that the perennial best-sellers are time management books like Eat That Frog or Getting Things Done. Every guru has a system, but it can be tricky to know which one is suitable for you. Thankfully, we can refer to those computer science nerds again to find optimal solutions.

GOALS 

The first step in evaluating a system is knowing how you’re keeping score. This is a theme across all computer science – before you have a plan, you must first choose a metric.

  • (A) Minimising maximum lateness 

If ‘lateness’ is how overdue the task is, and maximum lateness on a range of tasks is the furthest something has gone overdue, then one goal would be to ‘minimise maximum lateness. We don’t want any single task to go way overdue. If this is the goal, then the winning system would be the ‘earliest due date’. You start with the task that is due the soonest and work through the list, with the last item being the thing that’s due last. Therefore, each time you finish something and tick it off the list, you’re eliminating it from going further overdue.

  • (B) Minimising the number of tasks that go overdue

Think of getting a delivery of a box of fruit and vegetables every fortnight as an example. The meaning of ‘lateness’ here is a food item going rotten. In this scenario, we want to minimise the NUMBER of food items that go rotten, so the previous strategy would be irrelevant. Once it’s rotten, you can’t eat it, so making it more rotten doesn’t matter. A strategy that’s optimal for this goal is called ‘Moore’s Algorithm’. If you order the items based on the expiry date, you would eat the next-to-go rotten, eating them before they spoil and leaving the items that still have more time on the clock.

However, there is flexibility. As soon as something looks like it’s going to be late (you won’t be able to finish that food item in time), you throw it out and move on to the next one. The sooner you do this, the better. It means you’re not wasting time on something that will go rotten anyway, and you’re moving on to things that you can eat in time. This may mean throwing out the massive pumpkin that you won’t finish in time and moving on to the smaller potatoes that have a longer shelf life.

This strategy is optimal for minimising the number of tasks that go overdue. In the food scenario, we’re minimising the number of items you need to throw out (get rid of one big item to save four smaller ones). The problem here is you ignore anything that won’t be done on time. For example, you can’t boot something off the list and ignore it in a workplace setting.

  • (C) Getting as much stuff done as quickly as possible

Sometimes we neglect the due dates and focus on volume, maximising our output and ticking as much off the list as we can. This is when subgoals come in handy to our aid.

  • (D) Minimising the sum of completion times

Suppose you have two tasks for two separate clients at the start of the week, a 4-day task and a 1-day task. If you opted to do the longer task first, then the first client would wait 4 days and the second client 5 days. In total, the waiting time would be 9 days. But if you did the shorter task first, the client would wait 1 day while the other 5 days. You end up saving 3 days of waiting time.

If you want to minimise the ‘sum of completion times’, you should order the tasks according to ‘shortest processing time’. This allows you to tick the most tasks off your to-do list the quickest – sometimes, when you’ve got a mammoth list in front of you, it can be satisfying to knock off 3 or 4 items in a day and shrink the perceived length of your list.

  • (E) Putting out fires 

From time to time, a fire can land in our inbox. A super demanding client, an urgent task, or someone dissatisfied with your last project together. In this case, even though the fire may take longer to put out, it can be worth it in the end. The optimal strategy here is ‘weighted completion times’. You start by ranking tasks according to the shortest processing time, but you assign each task a ‘weight’ of importance. Considering both the processing time and the level of importance, you may shuffle your list around accordingly. Some tasks might take longer, but the overall value of completing them sooner may override the order of the list. The rule here is to prioritise a twice as long task if it’s more than twice as important.

A good example would be the Dave Ramsey ‘debt snowball/ avalanche’ analogy. The optimal strategy that minimises the interest is to pay off the debt with the highest interest rate. But the optimal psychological approach is shortening the list of debts by paying off the smallest one first. The goal isn’t to reduce the AMOUNT of debut, but the NUMBER of debts instead. By crossing items off the list, you gain confidence to keep going with your savings plan. This is an application of the ‘shortest processing time’ – the smallest debt is the quickest to pay off. So when it comes to completing lists and finding the ‘optimal’ productivity strategy, it boils down to picking your goals so that you can be productive.

Get Your Copy of Algorithms To Live By by Brian Christian & Tom Griffiths