Basically, I create a nested list where I store each node's child vertexes in different elements(eg: indexes of the child vertexes of the root node are in the 0th element/ the first element) of the list. Then, I remove the index of the child vertex (if that child vertex has further children) from the element associated with the parent vertex.
For eg: if 1 had 3 children, 2 3 and 4, and if 2 had further children, then we remove 2 from the element associated with the root, i.e. the 0th element in the list.
so before change -> [[2,3,4],[5,6,7]] after change -> [[3,4],[5,6,7]]
I'd appreciate the help especially since I'm a noob at coding :)