Let look at a graph
Code: Select all
0----1---
| |----4----5
2----3---
3 connect to 4, 4 connect to 5
If we represent this to a tree with 0 is the root then
0. 1 2
1. 4
2. 3
3. 4
4. 5
1 and 2 are the children of 0. 4 is the child of . 3 is the child of 2 and so on. Keep in mind that we can have more than 2 children (not a binary tree). So I represent this tree using adjacency list. My question is, with this same data, how do I make a tree root 1, more general., picking a number, how do I make a tree with that number is a root. What data structure do I use? I am not even sure how do I construct the input data to represent that graph above.