Author |
Topic: Merging a forest (Read 1294 times) |
|
first
Newbie
Posts: 22
|
|
Merging a forest
« on: Mar 8th, 2008, 3:27am » |
Quote Modify
|
A given tree can be broken into a forest by splitting the tree at various nodes. Here splitting means that the node at which you split become a leaf node of the original tree and also the root of the next tree. So given such a forrest: Given an algorithm to efficiently merge such a forest back into a tree in O(n).
|
|
IP Logged |
|
|
|
mad
Junior Member
Posts: 118
|
|
Re: Merging a forest
« Reply #3 on: Mar 9th, 2008, 10:33pm » |
Quote Modify
|
Could you explain what you mean?
|
|
IP Logged |
|
|
|
towr
wu::riddles Moderator Uberpuzzler
Some people are average, some are just mean.
Gender:
Posts: 13730
|
|
Re: Merging a forest
« Reply #4 on: Mar 10th, 2008, 2:07am » |
Quote Modify
|
on Mar 9th, 2008, 10:33pm, mad wrote:Could you explain what you mean? |
| Put all leaf nodes in the hashmap, then for each root node, if it matches a leaf node, add the left and right subtree of the root node to the leaf and clear the entry from the hashmap.
|
|
IP Logged |
Wikipedia, Google, Mathworld, Integer sequence DB
|
|
|
|