Tree Ring Order Traversal
If a connected graph doesn't have cycle, it's a tree.
Here by ring-order traversal, I mean visiting the leaf nodes first (i.e. 1st ring nodes), then the non-leaf nodes next to 1st ring nodes (i.e. 2nd ring nodes), and so on.
Algorithm
We keep track of indegrees of nodes. Remove those with indegrees 1 from the graph and update the indegrees of the remaining nodes. We keep doing this until exhausting all the nodes.
Implementation
The following solution is for 310. Minimum Height Trees (Medium) which is asking for the nodes
Problems
Last updated