Access Millions of academic & study documents

What is a graph

Content type
User Generated
Showing Page:
1/3
What is a graph?
A graph is made out of nodes and directed edges which defines a connection from one node to
another node. A node or vertex is a discrete position in a graph. Edges can be directed or
undirected. Edges have an associated distance also called costs or weight. The distance between
two nodes a and b is labelled as [a,b].
Dijkstra's algorithm is a graph algorithm. It describes how to find the shortest path from one node to
another node in a directed weighted graph.
The idea of Dijkstra is simple.
Let the node at which we are starting be called the initial node. Let the distance of node Y be the distance from
the initial node to Y. Dijkstra's algorithm will assign some initial distance values and will try to improve them step
by step.
1. Assign to every node a tentative distance value: set it to zero for our initial node and to infinity for all
other nodes.
2. Set the initial node as current. Mark all other nodes unvisited. Create a set of all the unvisited nodes
called the unvisited set.
3. For the current node, consider all of its unvisited neighbors and calculate their tentative distances.
Compare the newly calculatedtentative distance to the current assigned value and assign the smaller
one. For example, if the current node A is marked with a distance of 6, and the edge connecting it with
a neighbor B has length 2, then the distance to B (through A) will be 6 + 2 = 8. If B was previously
marked with a distance greater than 8 then change it to 8. Otherwise, keep the current value.
4. When we are done considering all of the neighbors of the current node, mark the current node as visited
and remove it from theunvisited set. A visited node will never be checked again.
5. If the destination node has been marked visited (when planning a route between two specific nodes) or
if the smallest tentative distance among the nodes in the unvisited set is infinity (when planning a
complete traversal; occurs when there is no connection between the initial node and remaining
unvisited nodes), then stop. The algorithm has finished.
6. Otherwise, select the unvisited node that is marked with the smallest tentative distance, set it as the new
"current node", and go back to step 3.

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/3
Dijkstra partitions all nodes into two distinct sets. Unsettled and settled. Initially all nodes are in the
unsettled sets, e.g. they must be still evaluated. A node is moved to the settled set if a shortest
path from the source to this node has been found.
Initially the distance of each node to the source is set to a very high value.
First only the source is in the set of unsettledNodes.
The algorithms runs until the unsettledNodes are empty. In earch iteration it selects the node with
the lowest distance from the source out the unsettled nodes. If reads all edges which are outgoing
from the source and evaluates for each destination node in these edges which is not yet settled if
the known distance from the source to this node can be reduced if the selected edge is used. If this
can be done then the distance is updated and the node is added to the nodes which need
evaluation.
In pseudocode the algorithm can be described as follows. Please note that Dijkstra also
determines the pre-successor of each node on its way to the source. I leave that out of the pseudo
code to simplify it.
Foreach node set distance[node] = HIGH
SettledNodes = empty
UnSettledNodes = empty
Add sourceNode to UnSettledNodes
distance[sourceNode]= 0
while (UnSettledNodes is not empty) {
evaluationNode = getNodeWithLowestDistance(UnSettledNodes)
remove evaluationNode from UnSettledNodes
add evaluationNode to SettledNodes
evaluatedNeighbors(evaluationNode)
}
getNodeWithLowestDistance(UnSettledNodes){
find the node with the lowest distance in UnSettledNodes and return it
}
evaluatedNeighbors(evaluationNode){
Foreach destinationNode which can be reached via an edge from evaluationNode AND which is
not in SettledNodes {
edgeDistance = getDistance(edge(evaluationNode, destinationNode))
newDistance = distance[evaluationNode] + edgeDistance
if (distance[destinationNode] > newDistance) {
distance[destinationNode] = newDistance
add destinationNode to UnSettledNodes
}
}

Sign up to view the full document!

lock_open Sign Up
Showing Page:
3/3

Sign up to view the full document!

lock_open Sign Up
Unformatted Attachment Preview
What is a graph? A graph is made out of nodes and directed edges which defines a connection from one node to another node. A node or vertex is a discrete position in a graph. Edges can be directed or undirected. Edges have an associated distance also called costs or weight. The distance between two nodes a and b is labelled as [a,b]. Dijkstra's algorithm is a graph algorithm. It describes how to find the shortest path from one node to another node in a directed weighted graph. The idea of Dijkstra is simple. Let the node at which we are starting be called the initial node. Let the distance of node Y be the distance from the initial node to Y. Dijkstra's algorithm will assign some initial distance values and will try to improve them step by step. 1. Assign to every node a tentative distance value: set it to zero for our initial node and to infinity for all other nodes. 2. Set the initia ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.
Studypool
4.7
Indeed
4.5
Sitejabber
4.4