Menu

Need Use Function Part Tried Execute Solution Give Wrong Answer Could Solution Python Need Q43859868

88% 23.06 + Answer 1 of 1 + Solution: 5.2) CODE: def edge_removal(adj_matrix, i, j): #function to remove the edge (j) from th

Why we need to use function for this part? When Itried to execute the solution its give me wrong answer?!

88% 23.06 + Answer 1 of 1 D + for elem in row: print(elem, end= ) print() 5.3) Algorithm: Step 1: For every element adj_mat

Could I have the solution in python? + do I need touse function for this step or call a function from part one of thequestion?

5.1 Listing all the edges (5 points) Write an O(na) program whose input is the adjacency matrix of a graph G. The program sho

88% 23.06 + Answer 1 of 1 + Solution: 5.2) CODE: def edge_removal(adj_matrix, i, j): #function to remove the edge (j) from the adjacency matrix adj_matrix[04) = 0 #simply setting the value of (j) in the matrix to 0 adj_matrix[i][j] = 0 #undirected graph needs (ji) to be set to 0 too, for removal of the edge for row in adj_matrix: #nested for loops to print the modified adjacency matrix for elem in row: print(elem, end=””) print) Screenshot for reference: def edge_removal(adj_matrix, i, j): adj_matrix[i][j] = 0 adj_matrix()][i] = 0 for row in adj_matrix: for elem in row: print(elem, end=” “) print) 5.3) 88% 23.06 + Answer 1 of 1 D + for elem in row: print(elem, end=” “) print() 5.3) Algorithm: Step 1: For every element adj_matrix[i][j] such that i + j < N, where N is the number of vertices, repeat steps 2-8 Step 2: Check whether the edge is present; If adj_matrix 0) != 1 then goto step 8 else step 3 Step 3:Set temp_matrix = adj_matrix Step 4: Remove the edge ((j) from the graph using, edge_removal(adj_matrix, i, j) Step 5: Check whether the resulting graph is connected or not; connected = Connect(adj_matrix). Connect() is the given method. Step 6: If connected == false then print the edge Step 7: Get back to the original matrix using, adj_matrix = temp_matrix Step 8: Get next element in adj_matrix Step 9: End Note: Step 1 involves the inclusion of elements from only the upper triangle to avoid repetition of edges in the undirected graph’s adjacency matrix. 5.1 Listing all the edges (5 points) Write an O(na) program whose input is the adjacency matrix of a graph G. The program should print the list of all the edges (without repetition). For example, if the vertices of the graph are 0,1,2,3,4,5 with O adjacent to 1 and 5, 1 adjacent to 5 2 adjacent to 3 and 4 and 3 adjacent to 4 then the printed list should be something like. OORNAM woon 5.2 Removal of an edge (5 points) Let G be a graph and e be an edge of G. We denote by Ge the graph obtained from G by removal fo e. That is, the vertices of Ge are the same as in G and the edges of Ge are all the edges of G but e. Write a program whose input is the adjacency matrix of a graph G and two vertices i and such that that are adjacent in G. The program should print the adjacency matrix of G{ij} (that is G with the edge between i and j being removed). 5.3 Listing all the bridges (10 points) Let G be a connected graph and e be an edge of G. We say that e is a bridge of Gif Ge is not connected (put it differently, the removal of e breaks the connectivity of G). Assume that we have a function Connect whose input is the adjacency matrix of a graph and the output is true if the graph is connected and false otherwise. Using this procedure, design an algorithm that prints all the bridges of G. Hint: Use the algorithm for the first part of that question for exploration of all the edges. Rather than printing the curretly considered edge straightaway, use the Connect procedure to check whether the given edges is a bridge (the Show transcribed image text 88% 23.06 + Answer 1 of 1 + Solution: 5.2) CODE: def edge_removal(adj_matrix, i, j): #function to remove the edge (j) from the adjacency matrix adj_matrix[04) = 0 #simply setting the value of (j) in the matrix to 0 adj_matrix[i][j] = 0 #undirected graph needs (ji) to be set to 0 too, for removal of the edge for row in adj_matrix: #nested for loops to print the modified adjacency matrix for elem in row: print(elem, end=””) print) Screenshot for reference: def edge_removal(adj_matrix, i, j): adj_matrix[i][j] = 0 adj_matrix()][i] = 0 for row in adj_matrix: for elem in row: print(elem, end=” “) print) 5.3)
88% 23.06 + Answer 1 of 1 D + for elem in row: print(elem, end=” “) print() 5.3) Algorithm: Step 1: For every element adj_matrix[i][j] such that i + j

Expert Answer


Answer to Why we need to use function for this part? When I tried to execute the solution its give me wrong answer?! Could I have…

OR