Big O Time Complexity

Trejon Stallsworth
Jun 24, 2020 · 2 min read

After graduating from my Software Engineering program at Flatiron school, I’ve been adjusting to the world of self teaching. One thing however, became evidently clear within the couple months leading up to graduation. Through the program and side courses I’ve taken, I know how to write code. But what separates good code from great code? Throughout my bootcamp we were taught to maintain the DRY principle (Don’t Repeat Yourself). This is a strong foundation for writing good code but as I quickly learned, that’s not all there is to it. While reading through “Cracking the Coding Interview”, a book I highly recommend, I was introduced to the concept of Big O Notation.

While diving into the topic, I came to the realization that this is an extremely important concept when it comes to programming. Big O Notation measures the quality of code by analyzing the time and space complexity of a given algorithm. As represented on the graph below, the more horizontal the line is the better the complexity is. For the purpose of this article, I’ll be specifically covering Big O Notation as it refers to time, not space.

Simply put, Big O Notation when referring to time complexity, describes the runtime of a given algorithm. As applications gain more traction, scalability becomes a huge factor. This is where Big O Notation plays an integral part. As data size increases, some algorithms can take longer to execute as now there are more pieces of the puzzle to evaluate. Therefore the more efficient we can make our code execute, the better.

As shown in the graph above, the primary Big O runtimes from fastest to slowest are: Constant O(1), Logarithmic O(log N), Linear O(n), Log Linear O(n log(n), Quadratic O(n²), Exponential O(2^n), and lastly Factorial O(n!). Rather than breaking down each runtime by definition which can be pretty math focused, I’ve learned a few tips to help me identify which I’m working with. Below I put together a list of basic definitions and hints for for each runtime.

After gaining a good sense of time complexity with Big O Notation, I’ve moved on to space complexity. Space complexity is caused by variables, data structures, function calls, and other memory allocations. I plan to further dive into this topic, as well as continue improving my use of time complexity to become a better programmer. Although I finished bootcamp, an exciting journey still awaits.

The Startup

Get smarter at building your thing. Join The Startup’s +724K followers.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

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