I have a dictionary-tree like this:
{ b : [e], a : [b,c], c : [], e : []}
How can I find the root(in this example 'a`) fast even if I have a very long dictionary?
Walk the adjacency list, put each "from" node into a set of source nodes, and each of its corresponding "to" nodes into a set of destination nodes.
Subtracting the set of destinations from the set of sources will yield one of the following:
Here is how this works for your example:
source
: { b, a, c, e }
destination
: { e, b, c }
source \ destination
: { a }