We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Data Structures
- Trees
- Jenny's Subtrees
- Discussions
Jenny's Subtrees
Jenny's Subtrees
Sort by
recency
|
16 Discussions
|
Please Login in order to post a comment
Here is an explained solution: 1. Cut the tree from each node to create a new subtree 2. Hash the new subtree in a unique way from the center (whether one node center or two) 3. Compare all the subtrees using hashes such as sets. 4. The unique hashes will indicate the unique subtrees. You can view an explanation here: Problem_Solving/Tree Isomorphism.ipynb in my github. MohamedYahiaSan
You will have to tune it for the proplem a little bit. However, it still doesn't answer the complexity for the last 4 tests. Another approach which is the best. However, it also didn't return perfct answers with me is to stack all leaves of the subtrees. Then starting form the leaves hash the tree in a unique way. However, it still doesn't overcome the time complexity for the last few tasks somehow!!
The first diagram in the description is incorrect. There are 2 nodes labelled 13. I was confused why they have 15 nodes and 15 edges. So actually they have 16 nodes and 15 edges.
I'm going with this definition of graph isomorphism: "an isomorphism is a vertex bijection which is both edge-preserving and label-preserving"
Essentially given 2 graphs A and B. If all the labelled nodes in A is equal to B and all edges in A are same as all edges in B.
omg i hate Time Error , I only got 7 tests correct/
here is hackerrank jenny's subtrees solution