Graph Algorithms Reference Sheet, Exercises of Algorithms and Programming

breadth-first-search() { make a queue of nodes. enqueue the start node. color the start node yellow. while (the queue is not empty) {.

Typology: Exercises

2022/2023

Uploaded on 05/11/2023

hugger
hugger 🇺🇸

4.8

(12)

916 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Graph Algorithms Reference Sheet
breadth-first-search() {
make a queue of nodes.
enqueue the start node.
color the start node yellow.
while (the queue is not empty) {
dequeue a node from the queue.
color that node green.
for (each neighboring node) {
if (that node is gray) {
color the node yellow.
enqueue it.
}
}
}
}
dijkstra's-algorithm() {
make a priority queue of nodes.
enqueue the start node at distance 0.
color the start node yellow.
while (the queue is not empty) {
dequeue a node from the queue.
if (that node isn't green) {
color that node green.
for (each neighboring node) {
if (that node is not green) {
color the node yellow.
enqueue it at the new distance.
}
}
}
}
}
aStarSearch() {
make a priority queue of nodes.
enqueue the start node at distance 0.
color the start node yellow.
while (the queue is not empty) {
dequeue a node from the queue.
if (that node isn't green) {
color that node green.
for (each neighboring node) {
if (that node is not green) {
color the node yellow.
enqueue it at the new distance plus the heuristic.
}
}
}
}
}
kruskals-algorithm() {
remove all edges from the graph.
put each node into its own cluster.
for (each edge, in increasing order of cost) {
if (the edge’s endpoints are in different clusters) {
add that edge back to the graph.
merge those two clusters.
}
}
return the edges added back.
}

Partial preview of the text

Download Graph Algorithms Reference Sheet and more Exercises Algorithms and Programming in PDF only on Docsity!

Graph Algorithms Reference Sheet

breadth-first-search() { make a queue of nodes. enqueue the start node. color the start node yellow. while (the queue is not empty) { dequeue a node from the queue. color that node green. for (each neighboring node) { if (that node is gray) { color the node yellow. enqueue it. } } } } dijkstra's-algorithm() { make a priority queue of nodes. enqueue the start node at distance 0. color the start node yellow. while (the queue is not empty) { dequeue a node from the queue. if (that node isn't green) { color that node green. for (each neighboring node) { if (that node is not green) { color the node yellow. enqueue it at the new distance. } } } } } aStarSearch() { make a priority queue of nodes. enqueue the start node at distance 0. color the start node yellow. while (the queue is not empty) { dequeue a node from the queue. if (that node isn't green) { color that node green. for (each neighboring node) { if (that node is not green) { color the node yellow. enqueue it at the new distance plus the heuristic. } } } } } kruskals-algorithm() { remove all edges from the graph. put each node into its own cluster. for (each edge, in increasing order of cost) { if (the edge’s endpoints are in different clusters) { add that edge back to the graph. merge those two clusters. } } return the edges added back. }