views:

34

answers:

2

I am working with the tree data structure and trying to come up with a way to calculate information I can gain from the nodes of the tree.

I am wondering if there are any existing techniques which can assign higher numerical importance to a node which appears less frequently at lower level (Distance from the root of the tree) than the same nodes appearance at higher level and high frequency.

To give an example, I want to give more significance to node Book, at level 2 appearing once, then at level 3 appearing thrice.

Will appreciate any suggestions/pointers to techniques which achieve something similar.

Thanks,

Prateek

A: 

One metric I just thought of is this: for a labelk, let it's "value" be the sum of the levels it appears at. So, if it appears at the root and the root's left child, let it's value be 1.

Then, your most "important" labels are those with the lowest value.

EDIT: This will make the root more important than the label of it's children, even if they are both the same. So, some scaling by occurrence count might be in order.

Precision
+1  A: 

It depends how much significance you want to give to it at each level.

Just multiply by a number that decreases as you move down the levels of the tree. For example, n_nodes * 1/(3^n), where n is the level of the tree. Thus, a node on level 2 gets a value of 1/4, and 3 nodes on level 3 get a value of 1/9. Thus, the single node on level 2 is more significant.

Adjust the denominator to your liking. As long as it increases with n, it will give more significance to nodes higher in the tree.

WhirlWind