Connected Components – The one Graph Algorithm you need to know
mlwhiz.com
mlwhiz.com
> You can think of Connected Components in very layman's terms as sort of a hard clustering algorithm which finds clusters/islands in related/connected data. As a concrete example: Say you have data about roads joining any two cities in the world. And you need to find out all the continents in the world and which city they contain.
The article doesn't contain a concise pseudo-code description of the algorithm but instead sneaks up on it by throwing in lots of python that implements various graph operations.
True, that's really a lot of code while failing to outline the simple algorithm or concisely describe the basic idea. It doesn't mention complexity either, which is linear.
It might also help beginners to mention the image analogue, i.e. connected components of a regular grid graph, which is called 'flood fill'.
> In case people are wondering, the algorithm is 'connected clustering'
FWIW, I've always heard the algorithm called 'connected components', and a quick Google search on both terms gives me more relevant hits for 'connected components'. In fact, I don't get a single directly relevant hit that describes this algorithm on the first page for 'connected clustering'.
Breadth First Search is a freshman year concept at many schools. Sophomore at the latest.
On the other hand it gives me some respect for people who have to learn this all themselves. Having 4 years to take off from work and just learn this stuff is a huge luxury and not necessary in a lot of cases. But at least for me I am very thankful for the structure of a formal degree. I don't think I could have self-taught all of this.
Given that, I studied many of the standard CS algos when I was brushing up for a FAANG interview. I found this gem of a guide: https://bradfieldcs.com/algos/ and after working through the examples, I could understand the behavior and underlying mechanisms of these algorithms. which completely helps when reading about articles like this!
Anyway, I think one would only be at a disadvantage if they are not seeking to continuously learn & satiate one's curiosity.
In the context of data analytics a SCC finding algo can be used to identify bottlenecks of communication/transportation networks and fault tolerance of distributed networks. In this case we are particularly interested in edges that connect SCCs. Another application is clustering. For instance, finding clusters of accounts that all follow each other on Twitter. In this case each such cluster is a SCC.
Kosaraju–Sharir algorithm is an easy to understand SCC algorithm with linear running time that basically consists of two BFS passes.
P.S. NetworkX (https://networkx.github.io/) is a great Python library for working with graphs. It has implementations of many common graph algos including SCC finding algorithm (it is an implementation of Tarjan's algorithm).
This is a nice implementation of classical graph problems.
Stuff like traveling salesman etc. Dijkstras algorithm.
The bit I am missing is how does this help me solve a day to day problem?
how can this be applied in something modern other than say a shortest path / route finding algorithm?
I suppose it's a way to reach an end point most efficiently and that makes it useful for nueral nets which are essentially tree's with weighted edge values.
the easiest path through the tree is something you could find and that might illuminate a route to optimizing your "thing" whatever that is.
Am I getting the idea of this right or not? ....
So it’s just a cleaner way of storing data relationships that allows for more questions to be asked like “show me all the labs with automated backups” or “show me how many nurses work weekends at more than one lab”
For this to be a nice implementation, they should use the standard library deque for the BFS or just pop from the end of the list to do a more efficient DFS for the connected component algorithm.