Algorithm to aggregate values from child tree nodes
Posted
by user222164
on Stack Overflow
See other posts from Stack Overflow
or by user222164
Published on 2010-03-24T17:18:21Z
Indexed on
2010/03/24
17:23 UTC
Read the original article
Hit count: 356
I have objects in a tree structure, I would like to aggregate status information from children nodes and update parent node with aggregated status. Lets say node A has children B1, B2, and B1 has C1, C2, C3 as children. Each of the nodes have a status attribute.
Now if C1, C2, C3 are all complete then I would like to mark B1 as completed. And if C4, C5,C6,C7 are complete make B2 as complete. When B1 and B2 are both complete mark A as complete.
I can go through these nodes in brute force method and make updates, could someone suggest an efficient algorithm to do it.
A { B1 { C1, C2, C3}, B2 { C4, C5, C6, C7} }
© Stack Overflow or respective owner