As a Linux user, I'm used to using various tiny tools to solve some problems
A day, When I meant to type cr, my abbreviation for clear, but I typed gc instead. Nothing happened, so I decided to find out what about this tiny tool to satisfy my curious and asked an LLM how to use it.
The Graph Theory tool
This tool is used to count graph components, and before this, I had never encountered graph theory but I seized this opportunity to learn about it. We can do a simple test
graph G {
A -- B;
B -- C;
D -- E;
F;
}
We will save this file as graph.dot and then gc -a graph.dot the output looks like this:
6331 G (graph.dot)
The simple options of gc include
-n Count nodes.
-e Count edges.
-c Count connected components.
-a Count all. Equivalent to -encC
And the output just means
Number
Meaning
6
Nodes
3
Edges
3
Connected components
1
Clusters
Node, Edge and Connected component
Connected component
The file graph.dot just like this
We can find that
Component 1: A can reach B and C
Component 2: D can reach E
Component 3: F has no any links, but it remains a separate connected component
What is nodes and edges?
Many things in the real world can be abstracted into a network
Every city is a node
The road connecting two cities is an edge
Everyone is a node
The relationship of two people is an edge
A Node is object and edge is relationship of two objects
Clusters
I also noticed that gc reported a parameter and I didn't understand what means about clusters, and I had no reason to continue exploring this parameter, so I decided to leave that question for next experiment
Maybe GC can help me like That
Imagine I am learning math, you can visualize the dependencies between different modules as a dependency graph
the derivatives depends on the function and an edge emerged
Then the gc and help us:
which module will depended each other?
Is the math module divied into several unrelated part?
This is only a conceptual example. I have not built this graph yet
Future Plans
I will not dive into graph theory so deep because I do not really understand what it could do yet
gc may be just a tiny tool but it may can lead a big idea
This made me wonder whether graph theory could also help me organize my knowledge
By the way, gc is a good kickstart of into graph theory, and I need to get the most out of those tools