Question

Question 6 15pt Given undirected positive edge weight graph G(V.E) and boo(m) = m3 while (v € VX for all u € Adj[v]) { boo(V)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

SOL:

Run time of the above code if the graph is stored as adj List:

The adjaceny List representation time complexity is O(V+E)

see in the first step while(u∈V) we are checking whether u belongs to Vertex set V or not . so This loop runs for V times

In the for loop for all u ∈ Adj[v] we are checking whether u belongs to adj[v] or not The adj[v] means E entries in the adjacency list for every vertex V.

so for every one time of the outer loop inner loop runs for E times. For every V inner loop runs for E times

so how many times the both loops run together is O(VE)

The time complexity of bool(V) is O(V3) as given in the question

so total time complexity is O(VEV3)

Run time fotr the above code if graph is stored as adj matrix:

The time complexity for the graph is stored as adj matrix is O(V2)

see in the first step while(u∈V) we are checking whether u belongs to Vertex set V or not . so This loop runs for V times

In the for loop for all u ∈ Adj[v] we are checking whether u belongs to adj[v] or not The adj[v] means V entries in the adjacency list for every vertex V.

so for every one time of the outer loop inner loop runs for V times. For every V inner loop runs for V times

so how many times the both loops run together is O(V2)

The time complexity of bool(V) is O(V3) as given in the question

so total time complexity is O(V2V3) = O(V5)

Add a comment
Know the answer?
Add Answer to:
Question 6 15pt Given undirected positive edge weight graph G(V.E) and boo(m) = m3 while (v...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Question 6 15pt Given undirected positive edge weight graph G(V.E) and boo(m) = m3 while (v...

    Question 6 15pt Given undirected positive edge weight graph G(V.E) and boo(m) = m3 while (v EVX for all u € Adj [y]) { boo(V); سبه یه What is the run-time of the code above given the Graph is store as adj. list? What is the run-time of the code above given the Graph is store as adj. matrix? Please explain your answer.

  • IN JAVA Given is a weighted undirected graph G = (V, E) with positive weights and...

    IN JAVA Given is a weighted undirected graph G = (V, E) with positive weights and a subset of its edges F E. ⊆ E. An F-containing spanning tree of G is a spanning tree that contains all edges from F (there might be other edges as well). Give an algorithm that finds the cost of the minimum-cost F-containing spanning tree of G and runs in time O(m log n) or O(n2). Input: The first line of the text file...

  • NP-completeness. We are given an undirected graph where each edge has a positive weight. Given (k,...

    NP-completeness. We are given an undirected graph where each edge has a positive weight. Given (k, alpha), the problem asks whether there is a subgraph with k nodes such that the total weight of the edges in the subgraph is at least alpha. Prove this problem is NP-Complete.

  • You are given an undirected graph G = (V, E) with positive weights on the edges....

    You are given an undirected graph G = (V, E) with positive weights on the edges. If the edge weights are distinct, then there is only one MST, so both Prim’s and Kruskal’s algorithms will find the same MST. If some of the edge weights are the same, then there can be several MSTs and the two algorithms could find different MSTs. Describe a method that forces Prim’s algorithm to find the same MST of G that Kruskal’s algorithm finds.

  • 2. Let G = (V, E) be an undirected connected graph with n vertices and with...

    2. Let G = (V, E) be an undirected connected graph with n vertices and with an edge-weight function w : E → Z. An edge (u, v) ∈ E is sparkling if it is contained in some minimum spanning tree (MST) of G. The computational problem is to return the set of all sparkling edges in E. Describe an efficient algorithm for this computational problem. You do not need to use pseudocode. What is the asymptotic time complexity of...

  • Reachability. You are given a connected undirected graph G = (V, E ) as an adjacency...

    Reachability. You are given a connected undirected graph G = (V, E ) as an adjacency list. The graph G might not be connected. You want to fill-in a two-dimensional array R[,] so that R[u,v] is 1 if there is a path from vertex u to vertex v. If no such path exists, then R[u,v] is 0. From this two-dimensional array, you can determine whether vertex u is reachable from vertex v in O(1) time for any pair of vertices...

  • Question 1: Given an undirected connected graph so that every edge belongs to at least one...

    Question 1: Given an undirected connected graph so that every edge belongs to at least one simple cycle (a cycle is simple if be vertex appears more than once). Show that we can give a direction to every edge so that the graph will be strongly connected. Question 2: Given a graph G(V, E) a set I is an independent set if for every uv el, u #v, uv & E. A Matching is a collection of edges {ei} so...

  • Help !! I need help with Depth-First Search using an undirected graph. Write a program, IN JAVA, ...

    Help !! I need help with Depth-First Search using an undirected graph. Write a program, IN JAVA, to implement the depth-first search algorithm using the pseudocode given. Write a driver program, which reads input file mediumG.txt as an undirected graph and runs the depth-first search algorithm to find paths to all the other vertices considering 0 as the source. This driver program should display the paths in the following manner: 0 to ‘v’: list of all the vertices traversed to...

  • Consider an unweighted, undirected graph G = 〈V, E). The neighbourhood of a node u E V in the gr...

    Consider an unweighted, undirected graph G = 〈V, E). The neighbourhood of a node u E V in the graph is the set of all nodes that are adjacent (or directly connected) to v. Subsequently, we can define the neighbourhood degree of the node v as the sum of the degrees of all its neighbours (those nodes that are directly connects to v) (a) Design an algorithm that returns a list containing the neighbourhood degree for each node v V,...

  • B-1 Graph coloring Given an undirected graph G (V. E), a k-coloring of G is a function c : V → {0, 1, . . . ,k-1}

    B-1 Graph coloring Given an undirected graph G (V. E), a k-coloring of G is a function c : V → {0, 1, . . . ,k-1} such that c(u)≠c(v) for every edge (u, v) ∈ E. In other words, the numbers 0.1,... k-1 represent the k colors, and adjacent vertices different colors. must havec. Let d be the maximum degree of any vertex in a graph G. Prove that we can color G with d +1 colors.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT