What's an algorithm, anyway?
Software plays an increasingly important role in our lives. We benefit from the work of thousands of developers on a daily basis.
An algorithm can be described as a sequence of steps for accomplishing a task. Algorithms process vast amounts of data to drive services in domains such as navigation, retail, social media, finance, and online dating.
Here's a flowchart depicting a friendship algorithm from the television show The Big Bang Theory:
This humorously illustrates the character's attempt to distill the art of making friendships into an algorithm. However, it does accurately depict how an algorithm works by making decisions based upon inputs.
Algorithms in Daily Life
Your Fitbit can gently wake you up in the morning with a vibration. How does it know you're sleeping and when to wake you up?
The tracker records your movements and an algorithm determines when sleep has begun when you haven't moved in a certain number of minutes. It also takes cues from the length of time your movements are indicative of sleep behavior (e.g. rolling over).
You reach for your phone to check your favorite social media network. The news feed appears and displays all the interesting posts you missed while you were away. This feed is curated by an algorithm that decides which posts would be most meaningful to you based on your past activity (likes, friends, followers, comments).
Before you leave the house, you turn on the Roomba to clean the living room while you're gone. The autonomous robot vacuum uses an algorithm to ensure it covers every square foot of the floor. These devices rely on a few simple algorithms such as spiral cleaning, room crossing, wall-following and angle-changing after bumping into an object or wall.
You step into the car to drive to work and open Google Maps to check the traffic. The app notices an accident on the main road and shows a quicker route to take. Navigation services use graph algorithms to determine the shortest route between two points on a map.
A graph is a data structure that lets you model pairwise relationships between objects.
Each point on the graph is a location, and each road is called an "edge" that connects each location. The longer it takes to drive down a road (speed limit/traffic/construction), the higher the "cost" of an edge is. The question the algorithm tries to answer is:
What's the path with the least cost to get from point A (your location) to point B (destination) within the graph?
The challenging part for the service is accurately fetching real-time information about traffic on the roads. It aggregates the data collected from Location Services on users' phones to determine how slow or fast people are moving on the roads. This provides a near real-time view into the traffic patterns around your area.
You may need to research a topic or figure out a problem using a Google search. Google's PageRank algorithm searches an index of ~60 trillion webpages and returns the results to you in less than a second.
You return home after work and decide to unwind in front of the television. The recommendations you see on Netflix and Amazon Prime Video are powered by algorithms that analyze the correlation between the programs you watched and ones that you may be interested in.
Online dating is now a multi-billion dollar industry due to the growth of sites like Match.com, OKCupid, and eHarmony. These sites pride themselves on their ability to connect users based on a compatibility rating that factors personality traits, values, and interests.