88. Algorithmic Complexity

Topics covered
Popular Clips
Episode Highlights
Nested Loops
Nested loops in algorithms can significantly impact complexity, often resulting in O(n^2) time complexity. Joe Zack explains that when both loops iterate over the same collection, the complexity becomes n times n, or n squared 1. This is a common scenario in algorithms like bubble sort, where each element is compared to every other element, leading to inefficiencies 1. Michael Outlaw highlights that recognizing these patterns is crucial, especially in interviews where optimizing from O(n^2) to O(n log n) is often expected 2.
If you can't look at it and say, oh, that's n square o of n squared, then that's going to be like rule number one.
--- Joe Zack
Understanding these complexities helps in identifying potential optimizations and improving algorithm efficiency.
Recursion Challenges
Recursion, while powerful, often comes with pitfalls that can lead to inefficiencies, particularly in terms of space complexity. Joe Zack warns that recursion should be a red flag due to potential stack space issues, especially when iterating over the same collection repeatedly 3. A classic example is the Fibonacci sequence, where naive recursive solutions can result in exponential time complexity, as the same computations are redundantly repeated 4. Michael Outlaw notes that these inefficiencies often arise when developers attempt to over-modularize code, leading to excessive function calls and poor performance 4.
If you find yourself doing recursion, that should already be a red flag in terms of space.
--- Joe Zack
Recognizing these red flags is essential for writing efficient and scalable code.
Related Episodes

What is Algorithmic Complexity?
Answers 383 questions89. Does Big O Matter?
Answers 383 questionsUnderstanding Complexity Theory
Answers 383 questions

Algorithms You Should Know
Answers 383 questionsGraph Algorithms
Answers 383 questionsClean Code - How to Write Amazing Functions
Answers 383 questionsDesigning Data-Intensive Applications – Scalability
Answers 383 questionsHow to be a Programmer
Answers 383 questionsHow to be an Advanced Programmer
Answers 383 questions87. Thunder Talks
Answers 383 questionsDesign Patterns Part 1
Answers 383 questions95. Data Structures – Arrays and Array-ish
Answers 383 questionsHow to be an Intermediate Programmer
Answers 383 questions

Technical Challenges of Scale at Twitter
Answers 383 questionsStackOverflow AI Disagreements, Kotlin Coroutines and More
Answers 383 questions













