Prufer Code to Tree Creation - GeeksforGeeks
What is Prufer Code?
Given a tree (represented as graph, not as a rooted tree) with n labeled nodes with labels from 1 to n, a Prufer code uniquely idetifies the tree. The sequence has n-2 values.
How to get Prufer Code of a tree?
- Initialize Prufer code as empty.
- Start with a leaf of lowest label say x. Find the vertex connecting it to the rest of tree say y. Remove x from the tree and add y to the Prufer Code
- Repeat above step 2 until we are left with two nodes.
Read full article from Prufer Code to Tree Creation - GeeksforGeeks
No comments:
Post a Comment