DAG descendant vertices tag sum

58 Views Asked by At

Hello I have a DAG with a tag per vertex. I want to write an algorithm to compute a per-vertex sum of the descendant vertices tags counting only once the repeated ones.

Tracking visited vertices works fine for one vertex. However if you want to know about other vertex, you need to start from scratch. Ideally what I need is to reuse data from a previous algorithm pass for the next one.

Right now I'm using functional programming to cache sums, invalidating results when tags change recursively, trying to pass visited nodes as pars too. However I feel that I'm going too far with this aproach as my solution gets more and more complex. I'm feeling that I'm computing lazy algorithms as results rather than numbers right now and I figured out it was about time to ask other people.

Any ideas are welcome.