Weighted matroid
In combinatorics, a branch of mathematics, a weighted matroid is a matroid endowed with a function that assigns a weight to each element. Formally, let be a matroid, where E is the set of elements and I is the family of independent set. A weighted matroid has a weight function for assigns a strictly positive weight to each element of. We extend the function to subsets of by summation; is the sum of over in.
Finding a maximum-weight independent set
A basic problem regarding weighted matroids is to find an independent set with a maximum total weight. This problem can be solved using the following simple greedy algorithm:- Initialize the set A to an empty set. Note that, by definition of a matroid, A is an independent set.
- For each element x in E\''A, check whether Au is still an independent set.
- * If there are no such elements, then stop, as A'' cannot be extended anymore.
- * If there is at least one such element, then choose the one with maximum weight, and add it to A.
Jack Edmonds proved that this simple algorithm indeed finds an independent set with maximum weight. Denote the set found by the algorithm by e1,...,ek. By the matroid properties, it is clear that k=rank, otherwise the set could be extended. Assume by contradiction that there is another set with a higher weight. Without loss of generality, it is possible to assume that this set has rank elements too; denote it by f1,...,fk. Order these items such that w ≥... ≥ w. Let j be the first index for which w > w. Apply the augmentation property to the sets and ; we conclude that there must be some i ≤ j such that fi could be added to while keeping it independent. But w ≥ w > w, so fi should have been chosen in step j instead of ej - a contradiction.
Example: spanning forest algorithms
As a simple example, say we wish to find the maximum spanning forest of a graph. That is, given a graph and a weight for each edge, find a forest containing every vertex and maximizing the total weight of the edges in the tree. This problem arises in some clustering applications. It can be solved by Kruskal's algorithm, which can be seen as the special case of the above greedy algorithm to a graphical matroid.If we look at the definition of the forest matroid, we see that the maximum spanning forest is simply the independent set with largest total weight — such a set must span the graph, for otherwise we can add edges without creating cycles. But how do we find it?
Finding a basis
There is a simple algorithm for finding a basis:- Initially let be the empty set.
- For each in
- * if is independent, then set to.
Extension to optimal
An independent set of largest total weight is called an optimal set. Optimal sets are always bases, because if an edge can be added, it should be; this only increases the total weight. As it turns out, there is a trivial greedy algorithm for computing an optimal set of a weighted matroid. It works as follows:- Initially let be the empty set.
- For each in, taken in decreasing order by weight
- * if is independent, then set to.
Complexity analysis
The easiest way to traverse the members of in the desired order is to sort them. This requires time using a comparison sorting algorithm. We also need to test for each whether is independent; assuming independence tests require time, the total time for the algorithm is.If we want to find a minimum spanning tree instead, we simply "invert" the weight function by subtracting it from a large constant. More specifically, let, where exceeds the total weight over all graph edges. Many more optimization problems about all sorts of matroids and weight functions can be solved in this trivial way, although in many cases more efficient algorithms can be found that exploit more specialized properties.
Matroid requirement
Note also that if we take a set of "independent" sets which is a down-set but not a matroid, then the greedy algorithm will not always work. For then there are independent sets and with, but such that for no is independent.Pick an and such that. Weight the elements of in the range to, the elements of in the range to, the elements of in the range to, and the rest in the range to. The greedy algorithm will select the elements of, and then cannot pick any elements of. Therefore, the independent set it constructs will be of weight at most, which is smaller than the weight of.