How do these 2 tree traversals differ?

Revision en1, by ora_ora, 2020-10-28 22:17:00

I was solving thisproblem. We are given a directed tree with every node reachable from 1(root). We calculate the number of leaf nodes and the sum of all weights of nodes in the subtree of each node. The thing is I took the tree as undirected because I was going to root at 1 anyway and do a dfs traversal — code, but this results in some node to have the number of leaves as 0(div by 0 error in code ultimately), the same code with the directed tree as in the Q works,here. I was wondering why? Arent these two traversals supposed to be the same as both trees are rooted at 1? Am I making some mistake in my implementation?

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English ora_ora 2020-10-29 12:48:30 1059
en2 English ora_ora 2020-10-29 12:47:49 527
en1 English ora_ora 2020-10-28 22:17:00 841 Initial revision (published)