Finding maximal spanning tree using Prim's algorithm - algorithm

Can we compute the maximal spanning tree by changing the algorithm to choosing the maximum vertex instead of choosing the minimum one?
I have come across the solution by negating the edges and applying the normal Prim's Minimum Spanning Tree algorithm.

Feed in to the algorithm the input graph, but with the weights negated. Nothing in Prim assumes the weights are positive. The minimum of the weights negated, is achieved by the maximum of the original weights.

Related

Given an unweighted graph how do I find a spanning tree with 1. Maximum number of leaves 2 minimum number of leaves

write an algorithm to find a spanning tree that has the maximum number of leaves.
Write an algorithm to find a spanning tree with minimum number of nodes.
I am yet not able to come up with a solution for the following questions.
For the first part what I thought is to find the vertex with the highest degree and place it in the second last level such that the last level gets the maximum number of leaves.
Finding a spanning tree of a graph with maximum number of leaves is an NP-Complete problem. There is a reduction from the Dominating Set Problem which is NP-Complete.
Finding a spanning tree of a graph with minimum number of leaves is also an NP-Complete problem. Suppose if the graph has a Hamiltonian path then the graph has a spanning tree with just two leaves. Thus finding a spanning tree of a graph with minimum number of leaves is equivalent to finding whether a graph has a Hamiltonian path or not.
So for both the problems you need to develop approximation algorithms.

Finding the minimum spanning tree of a graph using Kruskal's Algorithm

Here is a Graph where I need to find the minimum spanning tree of G using Prim's and Kruskal's algorithms.
I found the minimum spanning tree using Prim's algorithm. Here is my attempt.
I am having difficulty in finding the minimum spanning tree using Kruskal's algorithm. I have seen many videos related to Kruskal's graph algorithm but I ended up getting the same graph as Prim's algorithm.
Can anyone please show me how to find the minimum spanning tree of the graph using Kruskal's algorithm?
Prims and Kruskals will always give you the same answer if all the
edges of the graph have distinct weights, as there is only a single min-spanning tree that exists. For graph having many edges with
same weights, the algorithms could give you a different answer but not
always. Depends on the way the nodes are explored in the
implementation. This graph can have many different min-spanning trees.
As your graph has all distinct edge weights, you will always get the same answer.
Prim's and Kruskal's algorithm both find minimum spanning trees. Because the graph that you gave has edge weights that are all different from each other there will be no different spanning trees that are both minimum.as long as both algorithms are correctly implemented they will find the same tree. meaning there can be no variation between the MST.

Minimum Weighted Path Tree of an Undirected Graph

Assume that we have an undirected graph G=(V,E) and we have two nodes S and X.
Can we come up with an algorithm such that the largest weight of the edge on the path from S to X is minimized? Note that it is not the shortest path algorithm since we are not interested in minimizing their sum.
What is the complexity of this algorithm?
Is the minimum spanning tree algorithm (such as Prim) is a solution for the problem?
I don't know if minimum spanning tree will solve it or not, but it's certainly solvable by making some modifications to Dijkstra's algorithm.
Define the "length" of a path as the maximum edge in that path. Now find the shortest path from S to X using Dijkstra's algorithm. This is the path you are looking for.
Complexity is O((N+M)log N) if you use a binary heap and O(N * log N + M) with a Fibonacci heap.
Note that for this new definition of path length, if the length of a path is l, then adding an edge to the end of the path will not decrease it's length, since the maximum edge in that path can only increase. This property is necessary for Dijkstra's algorithm to work correctly.
For instance, if you were looking for the path with the shortest edge, then Dijkstra's algorithm will fail just like it fails when there are negative edges in the graph.
You can use minimum spanning tree (Prim's algorithm) to solve this problem. You will start with vertex S, then continue to build the tree using Prim's algorithm until you find X. Complexity will be O((V+E)*logV).
It will work because in the prim's algorithm you always choose the edge with minimum weight first.

Find a spanning tree with maximum number of edges with same weight

Here's the problem.
A weighted undirected connected graph G is given. The weights are constant. The task is to come up with an algorithm that would find the total weight of a spanning tree for G that fulfills these two conditions (ordered by priority):
The spanning tree has to have maximum number of edges with the same weight (the actual repeated weight value is irrelevant);
The total spanning tree weight should be minimized. That means, for example, that the spanning tree T1 with weight 120 that has at most 4 edges with the same weight (and the weight of each of those four is 15) should be preferred over the spanning tree T2 with weight 140 that has at most 4 edges with the same weight (and the weight of each of those four is 8).
I've been stuck on that for quite a while now. I've already implemented Boruvka's MST search algorithm for the graph, and now I'm not sure whether I should perform any operations after MST is found, or it's better to modify MST-search algorithm itself.
Any suggestions welcome!
This can be done naively in O(m^2), and without much effort in O(mn). It seems like it is possible to do it even faster, maybe something like O(m log^2(n)) or even O(m log(n)) with a little work.
The basic idea is this. For any weight k, let MST(k) be a spanning tree which contains the maximum possible number of edges of weight k, and has minimum overall weight otherwise. There may be multiple such trees, but they will all have the same total weight, so it doesn't matter which one you pick. MST(k) can be found by using any MST algorithm and treating all edges of weight k as having weight -Infinity.
The solution to this problem will be MST(k) for some k. So the naive solution is to generate all the MST(k) and picking the one with the max number of identical edge weights and then minimum overall weight. Using Kruskal's algorithm, you can do this in O(m^2) since you only have to sort the edges once.
This can be improved to O(mn) by first finding the MST using the original weights, and then for each k, modifying the tree to MST(k) by reducing the weight of each edge of weight k to -Infinity. Updating an MST for a reduced edge weight is an O(n) operation, since you just need to find the maximum weight edge in the corresponding fundamental cycle.
To do better than O(mn) using this approach, you would have to preprocess the original MST in such a way that these edge weight reductions can be performed more quickly. It seems that something like a heavy path decomposition should work here, but there are some details to work out.

Find a minimum weighted spanning tree of the Cycle graph

I'm trying to solve the problem presented above and here is my attempt:
Attempt: We can apply Dijkstra's shortest path algorithm instead of using Prim's and Kruskal's algorithms to find a MST as Dijkstra will visit all the nodes in the smallest weighted distance. Complexity: For G = (V,E), O(E log(V))
Questions:
(1) Is my approach correct ?
(2) Is it the most efficient answer to the question ?
If i'm completely wrong, I would appreciate a correct and efficient solution.
A cycle graph contains no edges other than those connecting the vertices in the cycle. So what we can do is iterate through all N edges and eliminate the maximum weighted edge forming a spanning tree of N - 1 edges containing the minimum sum of edges, forming a Minimum Spanning Tree.

Resources