I've faced this question as an exercise in my homework and I hope for help.
Given a directed tree $T = (V, E)$, Wewe need to find a set of vertices $A \subseteq V$ such that for every two vertices $v,u \in A$ that have aeither there is no path between them, the length of or the path between them is greater than 2of length at least 3. Furthermore, $A$ has toshould contain the maximummaximum number of vertices that satisfies what's written above.
So the point hereThe above is that if there are two vertices $v,u\in A$ and there isn'tan exercise in my homework. "A directed tree" means a path between them then it's still legal vertices,rooted tree where all edges are directed away from the condition here isroot. Note that if there is a path we need its length to be at least 3vertex in $T$ might have more than 2 children.
I think the approach here is Dynamic Programming since the graph given is a tree so we don't haveWe can use dynamic programming to check if there'scompute such a path between vertex and its children because is whatset for the tree implementssubtree rooted at each vertex of $T$. However, meaning there's no needI found a simple greedy algorithm.
- Create an empty set $A$.
- As long as $V\neq \emptyset$, repeat the following action.
- Add all leaves to $A$.
- Remove their parents and their grandparents from $V$ (and the edges that are connected to them from $E$).
- Return $A$.
It's easy to use $BFS$ or $DFS$ or any ofverify that all vertices added satisfy the known algorithmspath separating condition.
Note: The tree hasn't to be a binary tree, so every vertex can have multiple children and not only 2 I believe that the number of all vertices added is optimal. It is indeed true in all cases that I have tried. Is it true? Does the greedy algorithm always work? I would like to see a proof for it.