Crux of coding

KT
3 min readApr 23, 2021

Beautiful is when you know your algorithm and data structures with Big O notation.

Cracking DFS recursion is as fun as thinking about BFS queue when it comes to graph solutions. Traversing through nodes and edges, either a DAG or there’s a cycle, keeping all visited in consideration, you get to think about that Big O. And you wont stop until you make it better with memoization which can further brightens your numbers.

Now I can imagine on how Einstein would have felt when he imagined sitting on top of a light beam that is coming towards earth. It is the really that mental model that is beautiful and inspiring. When you realize that Dynamic Programming is nothing but a DFS is some conceptual graph it is how Srinivasa Ramanujan would have felt when he imagined Krishna telling him the magic of mathematics in his sleep.

Binary search on sorted data takes logarithmic time to respond to request. This simple sort and search approach saved lot of lookup timings. Knowing the lower and upper bounds feels limitless. That one problem to get to first bad version and power of lower bound made it clear simple is real. After solving Russian Doll, I couldn’t sleep thinking what a classic problem and how magically it can be solved using LIS and binary search.

Sequencing when represented as graph took us to Topological sort to resolve the dependencies or to spot the cycle in our connections. Backbone for our dependency management tools. You can establish sequence and validity of alien characters/codes using Topological sort, difficult to imagine, right? but not far from reach.

I used dictionary several times also wondered how google auto-completes my search sentence, never thought of magic of Trie, few well instrumented lines of code, irrespective of language you are using can serve the purpose.

When looking for maximum/minimum number, some of you like me will try to sort the numbers and find the max or min, but there’s a better approach, use min/max heap. The realization come to me when I got to know how SQL limit queries are optimized.

Approaching the problem can be “Greedy”, “Break down the problem into parts”, “Try reverse” or the best of all “See it as a Graph”. Come to think of it our earth, world, universe is collection of dots and connectors, everything can be seen as graph. On a busy road, or when in the downtown, look for those squares and rectangles in buildings and try to map it in 2D grid, you will be amazed to see its 2D representation and try to step into it to find the biggest rectangle and square.

I played Tic-Tac-Toe several times, not many moves it has, but it was more fun when I coded it in few mins :) Reading the fundamentals, going to the crux of the algorithm takes time but worth learning!

--

--