Before I start I am not so good with Graph Theory. However,
Quoting from Wikipedia,
Any connected graph without simple cycles is a tree. A forest is a disjoint union of trees.
While going through the source code of the JUNG library, I noticed the definition of forest as
public interface Forest<V,E> extends DirectedGraph<V,E>
Speaking on pure semantic level, is that not incorrect?
OR
Is there some specific reason why its done so? (like makes more sense/easy to understand in some algorithm implementation)
PS: I know that DirectedGraph
is just a tagging interface and does not declare any function. So, using DirectedGraph
instead of UndirectedGraph
does have any consequences (at least I see none).
JUNG's Forest
interface defines getChildren
and getParent
methods. These are methods that people generally expect to be associated with trees and forests, and don't make sense unless the graph is directed.
Furthermore, there isn't really a point to having a Forest or Tree interface without such method signatures. It is true that, in graph theory, a tree is simply a connected acyclic graph. But there aren't any methods (of general utility, at least) that apply to a tree with undirected edges that don't apply to graphs in general. That said, you could certainly create an implementation of Graph that constrains itself to be a tree with undirected edges--and you are free to do so.