Iβm @nyaomaru, a frontend engineer who is surprised by how cold it is in the Netherlands even though itβs still summer. πΈ
{% embed https://dev.to/nyaomaru/i-built-a-tool-to-visualize-dsa-lets-learn-together-dsa-view-view--djo %}
DSA View View allows you to understand DSA by visualizing how your implementation actually runs.
In the previous articles, we looked at problems like: Two Sum Binary Search Bubble Sort Valid Parentheses Reverse Linked List Maximum Depth of Binary Tree
{% embed https://dev.to/nyaomaru/is-learning-dsa-boring-lets-use-dsa-view-view-two-sum-binary-search-and-bubble-sort-374o %}
{% embed https://dev.to/nyaomaru/learn-valid-parentheses-reverse-linked-list-and-tree-max-depth-with-step-by-step-visualization-in-3o09 %}
This time, let's try three more classic problems: Number of Islands Invert Binary Tree Course Schedule
But how do we make the code understand that several 1s belong to the same island?
When the outer loops continue, there is no 1 left in that island to count again.
So, If we walk outside the grid, stop. If we reach water, stop. If we reach a cell we already changed to 0, stop.
In the worst case, the recursive call stack may grow with the number of land cells.
And then suddenly we see Why did that cell disappear? Which recursive call are we inside? Which cells belong to the current island? Where will the outer loop continue after recursion finishes?
{% embed https://dsa-view-view.vercel.app/#s=j.eyJlIjoibnVtYmVyLW9mLWlzbGFuZHMiLCJsIjoidHlwZXNjcmlwdCIsIm0iOiJ2ZXJpZmljYXRpb24iLCJ2IjoxfQ %}
The interesting thing is that each node only needs to know about its own two children.
But my brain immediately starts asking: Which root are we talking about now? Did node 2 already swap? Are we still going down? Or are we coming back up? What does left contain at this moment?
{% embed https://dsa-view-view.vercel.app/#s=j.eyJlIjoiaW52ZXJ0LWJpbmFyeS10cmVlIiwibCI6InR5cGVzY3JpcHQiLCJtIjoidmVyaWZpY2F0aW9uIiwidiI6MX0 %}
Once I can see that rhythm, the recursive solution feels much less magical. π³πΈ
When all prerequisites for a course are resolved, that course becomes available.
