Nodes minus merges
transcript
A graph has nodes and links. Some nodes are joined in groups. How many groups are there? Count them without a walk. Here is how.
Start with one group for each node. Read the links one at a time. A link may merge two groups.
Six nodes. Six groups. Link zero to one merges. Five. Link one to two merges. Four. Link zero to two does not. Still four. Link three to four merges. Three.
A merge lowers the count. A link inside one group closes a cycle.
This needs no walk at all. One pass over the links is enough. And the wasted links are the cycles.
A link inside one group is wasted. It means a cycle is closed. The cycles number m minus n plus c.
Node five has no link. It is a group of one. So the answer is three.
Count the merges. A link inside a group is a cycle. Isolated nodes count. Full breakdown in the lecture.