Interface TreePathMaxima
-
public interface TreePathMaxima
Tree Path Maxima (TPM) algorithm.Given a tree \(T\) and a sequence of vertices pairs \((u_1,v_1),(u_2,v_2),\ldots\) called queries, the tree path maxima problem is to find for each pair \((u_i,v_i)\) the heaviest edge on the path between \(u_i\) and \(v_i\) in \(T\).
TPM can be used to validate if a spanning tree is minimum spanning tree (MST) or not, by checking for each edge \((u,v)\) that is not in the tree that it is heavier than the heaviest edge in the path from \(u\) to \(v\) in the tree. If a TPM on \(n\) vertices and \(m\) queries can be answer in \(O(n + m)\) time than an MST can be validated in linear time.
Use
newInstance()
to get a default implementation of this interface. A builder obtained vianewBuilder()
may support different options to obtain different implementations.- Author:
- Barak Ugav
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
TreePathMaxima.Builder
A builder forTreePathMaxima
objects.static interface
TreePathMaxima.IQueries
Queries container forTreePathMaxima
computations forIntGraph
.static interface
TreePathMaxima.IResult
A result object forTreePathMaxima
algorithm forIntGraph
.static interface
TreePathMaxima.Queries<V,E>
Queries container forTreePathMaxima
computations.static interface
TreePathMaxima.Result<V,E>
A result object forTreePathMaxima
algorithm.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description <V,E>
TreePathMaxima.Result<V,E>computeHeaviestEdgeInTreePaths(Graph<V,E> tree, WeightFunction<E> w, TreePathMaxima.Queries<V,E> queries)
Compute the heaviest edge in multiple tree paths.static TreePathMaxima.Builder
newBuilder()
Create a new tree path maxima algorithm builder.static TreePathMaxima
newInstance()
Create a new tree path maxima algorithm object.static <V,E>
booleanverifyMST(Graph<V,E> g, WeightFunction<E> w, Collection<E> mstEdges, TreePathMaxima tpmAlgo)
Verify that the given edges actually form an MST of a graph.
-
-
-
Method Detail
-
computeHeaviestEdgeInTreePaths
<V,E> TreePathMaxima.Result<V,E> computeHeaviestEdgeInTreePaths(Graph<V,E> tree, WeightFunction<E> w, TreePathMaxima.Queries<V,E> queries)
Compute the heaviest edge in multiple tree paths.The
queries
container contains pairs of vertices, each corresponding to a simple path in the giventree
. For each of these paths, the heaviest edge in the path will be computed.If
g
is anIntGraph
, aTreePathMaxima.IResult
object is returned. In that case, its better to pass aIWeightFunction
asw
, andTreePathMaxima.IQueries
asqueries
to avoid boxing/unboxing.- Type Parameters:
V
- the vertices typeE
- the edges type- Parameters:
tree
- a treew
- an edge weight functionqueries
- a sequence of queries as pairs of vertices, each corresponding to a unique simple path in the tree.- Returns:
- a result object, with a corresponding result edge for each query
-
newInstance
static TreePathMaxima newInstance()
Create a new tree path maxima algorithm object.This is the recommended way to instantiate a new
TreePathMaxima
object. TheTreePathMaxima.Builder
might support different options to obtain different implementations.- Returns:
- a default implementation of
TreePathMaxima
-
newBuilder
static TreePathMaxima.Builder newBuilder()
Create a new tree path maxima algorithm builder.Use
newInstance()
for a default implementation.- Returns:
- a new builder that can build
TreePathMaxima
objects
-
verifyMST
static <V,E> boolean verifyMST(Graph<V,E> g, WeightFunction<E> w, Collection<E> mstEdges, TreePathMaxima tpmAlgo)
Verify that the given edges actually form an MST of a graph.The verification is done by computing for each original edge \((u, v)\) in the graph the heaviest edge on the path from \(u\) to \(v\) in the given spanning tree. If all of the edges which are not in the MST have a greater weight than the maximum one in the path of the MST, the MST is valid.
If
g
is anIntGraph
, its better to pass aIWeightFunction
asw
, andIntCollection
asedges
to avoid boxing/unboxing.- Type Parameters:
V
- the vertices typeE
- the edges type- Parameters:
g
- an undirected graphw
- an edge weight functionmstEdges
- collection of edges that form an MSTtpmAlgo
- tree path maximum algorithm, used for verification- Returns:
true
if the collection of edges form an MST ofg
, elsefalse
- Throws:
IllegalArgumentException
- ifg
is a directed graph
-
-