Solutions for Exercises - Dijkstra Algorithm | CS 455, Assignments of Computer Science

Material Type: Assignment; Class: Comp Communications/Networking; Subject: Computer Science; University: George Mason University; Term: Unknown 1989;

Typology: Assignments

Pre 2010

Uploaded on 02/10/2009

koofers-user-ig6
koofers-user-ig6 🇺🇸

7 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Solution to Exercises From 24 Mar 2004
1Using Djikstra’s algorithm, find the shortest path from node 1 to all other nodes [see slide 09.103
for network diagram]
We start with node 1, looking at the cost to reach each node directly reachable from 1. From all such paths
we select the lowest cost path, adding it to set R for the next iteration, and we repeat this until all nodes
are in the set R. The last path appearing in each column, i.e., before the node to which it is a path is added
to R, is the shortest path from our start node to that particular node. The table stops showing costs +path
entries once an entry is found that does not change (but I duplicate the entry for C6to show it as a ‘tie’ in
cost (6) for iteration 4.
Iteration R Path Path Path Path PathC2C3C4C5C6
1{1} 1 12? – 714? – ? –
2{1,2} 4 1237 14? – ? –
3{1,2,3} 7 145123561236
4{1,2,3,5} 6 1235461236
5{1,2,3,4,5}
6{1,2,3,4,5,6}
2Repeat using the Bellman-Ford algorithm.
[Shay describes this algorithm on pages 459 - 466 (2nd ed.), 496 - 502 (3rd ed.). Tanenbaum (4th edition)
provides a description on pages 357-360].
With Bellman-Ford we explore, iteratively,ever longer length paths until our table of costs doesn’t change.
We start with a hop count, h,of0and ask what nodes we can reach in 0 hops; this iteration is easy.Next
we set hto 1 and ask what nodes we can reach in 1 hop and what their costs are: we select, for each node
we can reach, the lowest cost path we discover.Ateach iteration we ennumerate all the paths having a
length hop-count hfrom our origin, and update our list of costs if we discover a path to any of the nodes
that is less expensive than any path we already have.
Forinstance, all paths with 1 hop are:
Path Cost
121
147
Each of these paths is less expensive than the costs we now have, so both go in the table.
Paths with 2 hops are:
Path Cost
1234
14310
1458
Of the two paths to node 3, that via node 2 is least expensive, so that one enters the table. Paths involving
more hops but with lower cumulative cost may replace earlier discovered paths.
Continuing as above, we end up with the table shown below.
Hop Count Path Path Path Path PathC2C3C4C5C6
0∞ε∞ ε ∞ ε∞ε∞ ε
1112∞ε714∞ε∞ε
241238145∞ε
35123561236
4612354
CS455 1 Exercises from 24 Mar 2004

Partial preview of the text

Download Solutions for Exercises - Dijkstra Algorithm | CS 455 and more Assignments Computer Science in PDF only on Docsity!

Solution to Exercises From 24 Mar 2004

Using Djikstra’s algorithm, find the shortest path from node 1 to all other nodes [see slide 09.

for network diagram]

We start with node 1, looking at the cost to reach each node directly reachable from 1. From all such paths

we select the lowest cost path, adding it to set R for the next iteration, and we repeat this until all nodes

are in the set R. The last path appearing in each column, i.e., before the node to which it is a path is added

to R, is the shortest path from our start node to that particular node. The table stops showing costs + path

entries once an entry is found that does not change (but I duplicate the entry for C 6 to show it as a ‘tie’ in

cost (6) for iteration 4.

Iteration R C 2 Path C 3 Path C 4 Path C 5 Path C 6 Path

Repeat using the Bellman-Ford algorithm.

[Shay describes this algorithm on pages 459 - 466 (2nd^ ed.), 496 - 502 (3rd^ ed.). Tanenbaum (4th edition)

provides a description on pages 357-360].

With Bellman-Ford we explore, iteratively, ever longer length paths until our table of costs doesn’t change.

We start with a hop count, h , of 0 and ask what nodes we can reach in 0 hops; this iteration is easy. Next

we set h to 1 and ask what nodes we can reach in 1 hop and what their costs are: we select, for each node

we can reach, the lowest cost path we discover. At each iteration we ennumerate all the paths having a

length hop-count h from our origin, and update our list of costs if we discover a path to any of the nodes

that is less expensive than any path we already have.

For instance, all paths with 1 hop are:

Path Cost

Each of these paths is less expensive than the costs we now have, so both go in the table.

Paths with 2 hops are:

Path Cost

Of the two paths to node 3, that via node 2 is least expensive, so that one enters the table. Paths involving

more hops but with lower cumulative cost may replace earlier discovered paths.

Continuing as above, we end up with the table shown below.

Hop Count C 2 Path C 3 Path C 4 Path C 5 Path C 6 Path

0 ∞ ε ∞ ε ∞ ε ∞ ε ∞ ε 1 1 1 → 2 ∞ ε 7 1 → 4 ∞ ε ∞ ε 2 4 1 → 2 → 3 8 1 → 4 → 5 ∞ ε 3 5 1 → 2 → 3 → 5 6 1 → 2 → 3 → 6 4 6 1 → 2 → 3 → 5 → 4

CS455 1 Exercises from 24 Mar 2004