I recently subscribed to a fun weekly newsletter from Brandon Morrison called All Tests Pass. Every week, I receive a JavaScript puzzle inside a JSBin link and the following week, I can see how other people solved the same problem.

Most of the time, programming is about making the right trade-offs: are we optimizing for space or time?

Code Golf is a recreational style of programming that specifically optimizes for the length of the code. This means implementing an algorithm in the shortest number of characters. To that effect, some programming languages have comprehensive collections libraries that make it easy…


Algorithms for Everyone

In Part 1, we learned how to sort a collection of items in a way that mirrors how we think about sorting objects in real life.

We used an algorithm called selection sort, but when you use the sort function in your favorite language, it probably doesn’t use this algorithm. The reason is that it’s very slow.

How slow?

Let’s assume that we’re running our selection sort algorithm on a computer that takes 1 second to sort a list with 1,000 items. …


Algorithms for Everyone

When discussing algorithms, computer scientists typically use Big-O notation. It’s the most common way to express algorithm performance, but it’s also the quickest way to confuse new programmers or developers without a computer science background.

If you’re trying to understand what this mystical O(…) abstraction means, the first thing you might try is a quick Google search:


Algorithms for Everyone

Sorting is the process of arranging or ordering things based on a specific property. For example, numbers can be ordered by their value: 1 is smaller than 2. If we order the list by ascending order, 1 comes before 2. We can also sort a list of numbers by descending order. In that case, 2 comes before 1.

However, sorting also occurs in the physical world. For example, we can sort objects by size. In the United States, Coinstar machines are vending machines that automatically sort and count coins for you. …


Algorithms for Everyone

If you’re a new to programming or a self-taught programmer, binary search might sound daunting or complex. After all, binary is the language that your computer speaks (ones and zeroes), right?

1101 1001 0001 1010 1010 0010 1100 01010 1000 0100

In this case, binary search refers to a “binary decision”, which means that every time we make a decision, we have two choices:

  • One choice leads us to whatever we’re looking for.
  • The other leads to a dead end.

The “trick” to binary search is knowing what question to ask.

In the game of “20 Questions”, players ask “Yes/No”…

Chris Nguyen

Web developer and Washington, DC native.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store