Concept explainers
Weighted Graph:
A graph is termed as weighted graph if each edge of the graph is assigned a weight. The weighted edges stored in the weighted graphs can be stored in adjacency lists.
Weighted edges can be represented using a two-dimensional array. An weighted edge can be represented as “WeightedEdge(u,v,w)”, where “u” and “v” are edges and “w” represents the weight between them.
Example of storing edge in a weighted graph:
Object[][] edges =
{ new Integer(0), new Integer(1), new SomeTypeForWeight(8) };
Prim’s
Prim’s Algorithm is a greedy algorithm that finds a minimum spanning tree for a weighted undirected graph by finding a subset of the edges that forms a tree that includes every vertex, where the total weight of all the edges in the tree is minimized.
Want to see the full answer?
Check out a sample textbook solutionChapter 29 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
- You have to run Prim's algorithm for the problem defined by adjacency matrix: 1 2 3 4 5 6 7 8 9 1 0 10 9 999 999 17 999 999 999 2 10 10 3 9 11 0 14 4 2 999 999 13 999 14 0 7 999 999 999 999 999 4 999 4 7 0 999 2 8 999 999 567 999 2 999 999 0 6 999 1 999 17 999 999 2 6 0 999 7 999 999 999 999 8 999 999 0 11 4 8 999 13 999 999 1 7 11 0 8 9 999 999 999 999 999 999 4 8 0 1. We started from the vertex vl, so initially we have Y = {v1}: initial nearest 1 2 3 4 5 6 7 8 9 16 1 1 1 1 1 1 1 1 distance -1 10 9 999 999 17 999 999 999 Print out the values stored in the nearest and distance arrays after first iteration of Prim's algorithm. Specify the value of vnear and the next vertex that has to be added to Y Hint: use (copy) the table above to record your answer.arrow_forwardWrite pseudocode to find all pairs shortest paths using the technique used in Bellman-Ford's algorithm so that it will produce the same matrices like Floyd-Warshall algorithm produces. Also provide the algorithm to print the paths for a source vertex and a destination vertex. Describe the properties of the algorithm you provide and the run time for your algorithm in detail.arrow_forwardHow to draw a a Sierpinski triangle of order n, such that the largest filled triangle has bottom vertex (x, y) and sides of the specified length?arrow_forward
- Scale a line between (2,1) and (4,1) to twice its length and draw a line before and after scaling.arrow_forwardUse loops to create a (8x8) matrix in which the value of each element is four times its row number minus three times its column number. solve code in matlabarrow_forwardUse Bresenham's line algorithm to draw a line with end points (25,20) and (15,10).arrow_forward
- Apply Floyd's algorithm to the following graph. Write Dó matrix as your answer. 2 3 6 4 2. 2. Your answer 4. to 5.arrow_forwardSimplify the following expression to products of sums using k maps and don't care F = (x, y, z) = E(0, 1, 4, 5, 6); d(2, 3, 7)arrow_forwardPlease choose the correct answerarrow_forward
- Write a program to create a matrix A(5*5), then replace the diagonal with zeros. Add “break” or “continue” when it is suitable. used matlabarrow_forwardUsing map() and reduce(), calculate 1 + 8 + 27 + ... + n 3 in pseudocode. (Use map() and reduce() as pseudo functions. No need to write MapReduce code.)arrow_forwardfindarrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education