Prev:
W6 , Next:
W8
Links:
Zoom ,
TopHat (010339, or
Form ), Calculator:
Eval
Slide:
Go All Prev Next
# Weighted Graphs
📗 Weighted edges assign a cost or weight to each edge.
📗 Cost of a path:
➩ For weighted graphs: sum of edge weights on path.
➩ For unweighted graphs: length of the paht (number of edges).
# Minimum Spanning Tree
📗 In a weighted graph:
➩ Minimum spanning trees are the spanning trees with the lowest sum of edge weights.
# Prim's Algorithm
📗 For weighted, connected, and undirected graphs.
📗 prim(v)
➩ pq = new PriorityQueue()
➩ mark v as visited
➩ pq.insert(v.outgoingEdges)
➩ while (!pq.isEmpty()):
➩ c = pq.removeMin()
➩ if (c.endNode is unvisited):
➩ mark c.endNode as visited
➩ add c to tree
➩ pq.insert(c.endNode.outgoingEdges to unvisited nodes)
# Prim's Algorithm Example
ID:
Confirm
📗 [1 point] Find a minimum spanning tree using
Prim
Kruskal
's Algorithm.
➩ Node names: and Adjacency matrix:
📗 Queue:
📗 Nodes:
# Kruskal's Algorithm
📗 For weighted, connected, and undirected graphs.
📗 kruskal(edgeList)
➩ sort edgeList
➩ init nodeSets with singleton sets
➩ while (!edgeList.isEmpty()):
➩ c = edgeList.removeFirst()
➩ if (c.startNode and c.endNode in different nodeSets):
➩ add c to tree
➩ nodeSets.join(c.startNode, c.endNode)
# Kruskal's Algorithm Example
ID:
Confirm
📗 [1 point] Find a minimum spanning tree using
Prim
Kruskal
's Algorithm.
➩ Node names: and Adjacency matrix:
📗 Queue:
📗 Nodes:
# Complexities
📗 V: number of nodes in graph.
📗 E: number of edges in graph.
📗 Prim: \(O\left(3 E \log E\right) = O\left(E \log V^{2}\right) = O\left(2 E \log V\right) = O\left(E \log V\right)\).
📗 Kruskal: \(O\left(E \log E + V + 2 E \log V\right) = O\left(E \log V^{2} + 2 E \log V\right) = O\left(2 E \log V + 2 E \log V\right) = O\left(4 E \log V\right) = O\left(E \log V\right)\).
# Dijkstra's Algorithm
📗 Finds the shortest (lowest-cost) path in a graph from start node to all other nodes.
📗 Is the fastest, single start, shortest path algorithm for directed and undirected graphs with unbounded, non-negative edge weights.
📗 dijkstra(v):
➩ pq = new PriorityQueue()
➩ pq.insert([dest:v, pred:null, cost:0])
➩ while(!pq.isEmpty())
➩ [dest, pred, cost] = pq.removeMin()
➩ if dest is unvisited:
➩ mark dest as visited, store pred and cost for dest
➩ for each edge with weight w to unvisited neighbor u of dest:
➩ pq.insert([u, dest, cost + w])
📗 Example:
# Dijkstra's Algorithm Example
ID:
Confirm
📗 [1 point] Find the shortest path from node A to every other node using Dijkstra's Algorithm.
➩ Node names: and Adjacency matrix:
📗 Queue:
📗 Nodes:
# HTML and CSS Example
📗 From Campus section:
Link .
➩ Right click -> "View page source".
# Readings
📗 HTML Introduction:
Link .
📗 HTML Tag Reference:
Link .
📗 CSS Properties Reference:
Link .
📗 CSS Selectors Reference:
Link .
📗 Develop an HTTP Server in Java:
Link .
📗 JS and Document Object Model (DOM) Reference:
Link .
test prm,ksk,dks l
📗 Notes and code adapted from the course taught by Professor Florian Heimerl and Ashley Samuelson
.
📗 Please use Ctrl+F5 or Shift+F5 or Shift+Command+R or Incognito mode or Private Browsing to refresh the cached JavaScript.
📗 You can expand all the examples and demos: Expand , or print the notes: Print .
📗 If there is an issue with TopHat during the lectures, please submit your answers on paper (include your Wisc ID and answers) or this Google
Form at the end of the lecture.
Prev:
W6 , Next:
W8
Last Updated: November 25, 2025 at 1:46 AM