Given an undirected graph that is a tree, give a linear time algorithm to find the two leaves in the tree that have the minimum distance between them.
Sol. Breadth-first search is an algorithm for traversing or searching tree or graph data structures. It starts at the tree root or some arbitrary node of a graph, sometimes referred to as a 'search key' and explores the neighbor nodes first, before moving to the next level neighbors.
The S set is used to track which vertices have been visited . At the beginning of the algorithm, the set is empty. At the end of the algorithm, it contains all vertices with a distance from root less than the goal.
The parent attribute of each vertex is useful for accessing the nodes in a shortest path, for example by backtracking from the destination node up to the starting node, once the BFS has been run, and the predecessors nodes have been set. The time complexity can be expressed as O(|V|+|E|) since every vertex and every edge will be explored in the worst case. |V|is the number of vertices and |E|is the number of edges in the graph.
BFS is an undirected graph that is a tree, give a linear time algorithm to find the two leaves in the tree that have the minimum distance between them.
Given an undirected graph that is a tree, give a linear time algorithm to find the...
You are given an undirected graph G with weighted edges and a minimum spanning tree T of G. Design an algorithm to update the minimum spanning tree when the weight of a single edge is increased. The input to your algorithm should be the edge e and its new weight: your algorithm should modify T so that it is still a MST. Analyze the running time of your algorithm and prove its correctness.
You are given an undirected graph G with weighted edges and a minimum spanning tree T of G. Design an algorithm to update the minimum spanning tree when the weight of a single edge is decreased. The input to your algorithm should be the edge e and its new weight; your algorithm should modify T so that it is still a MST. Analyze the running time of your algorithm and prove its correctness.
Given an undirected connected graph, give an efficient algorithm for generating a path that traverses each edge exactly twice. Explain the order of your algorith
Use Kruskals Algorithm to find the minimum spanning tree for the weighted graph. Give the total weight of the minimum spanning tree. What is the total weight of the minimum spanning tree? The total weight is _______
2. Use Prim's algorithm to find a minimum spanning tree for the following graph 3. Use Kruskal's algorithm to find a minimum spanning tree for the graph given in question.
Let G = (V, E, w) be a connected weighted undirected graph. Given a vertex s ∈ V and a shortest path tree Ts with respect to the source s, design a linear time algorithm for checking whether the shortest path tree Ts is correct or not.(C pseudo)
Given the graph above, use Kruska’s algorithm and Prim’s
algorithm to find the minimum spanning tree. Break ties using
alphabetical order (e.g., if edges have the same cost, pick (A, D)
over (A, G) and pick (A, H) over (C, F). Show the order of the
edges added by each algorithm.
Suppose you are given an undirected graph G. Find a pair of vertices (u, v) in G with the largest number of common adjacent vertices (neighbors). Give pseudocode for this algorithm and show the worst-case running time.
Give a linear-time algorithm to find an odd-length cycle in a directed graph. (Hint: First solve this problem under the assumption that the graph is strongly connected.)
Let G be an undirected graph and let X be a subset of the vertices of G. A connecting tree on X is a tree composed out of the edges of G that contains all the vertices in X. One way to compute a connecting tree consists of two steps: (1) Compute a minimum spanning tree T over G. (2) Delete all the edges out of T not needed to connect vertices in X. Give an algorithm(Pseudo-code) to carry out...