Wesley Silva’s Post

I've been studying Grokking Algorithms, and in the chapter about Big O notation, I had some trouble understanding the different notations. By coincidence, Augusto Galego (a YouTuber I really like), released a video explaining Big O, and it helped me a lot. Here’s what I learned: Time complexity refers to how long an algorithm takes to run, and space complexity refers to how much memory it uses. O(1) means constant complexity. The algorithm performs a fixed number of operations, no matter the size of the input. For example, accessing an element in an array by its index is O(1) because you know exactly where the element is, so the operation happens once. O(n) means the running time grows linearly with the input size n. If you have to go through an entire list to find an item, the number of operations depends on how many elements are in the list. O(log n) is a classic case for algorithms like binary search. Even as the input grows, the running time increases much more slowly proportional to the logarithm of the input size because the problem is divided in half at each step. O(n log n) is typical of efficient sorting algorithms like Merge Sort, Heap Sort, and Quick Sort. They divide the problem into smaller parts (log n times) and process all elements (n) in each division. O(n²) appears in algorithms with two nested loops, such as Bubble Sort. Each element is compared with every other element, so the number of operations grows quadratically with the input size. Because of that, these algorithms are recommended only for small lists. I’ve just finished the first chapter of the book, and it’s been a great start to understanding how algorithms really work. #BigO #AlgorithmComplexity #Programming #SoftwareDevelopment #Tech #ComputerScience

  • No alternative text description for this image

Great explanation Wesley. A practical example that always comes to mind in front-end development is the difference between using a .find() on an array (which is O(n)) and searching for a property in an Object or Map (which is O(1)).

Like
Reply

To view or add a comment, sign in

Explore content categories