|
| 1 | + |
| 2 | +## Exercise 2: |
| 3 | + |
| 4 | +### Statement: |
| 5 | + |
| 6 | +Applying Dijkstra's Algorithm to the Shortest Path Problem |
| 7 | + |
| 8 | +**Step 1:** Assign the value 0 to the source node (1) and ∞ (infinity) to all other nodes, as shown in the graph: |
| 9 | + |
| 10 | + |
| 11 | +INSERIR O GRAFO |
| 12 | + |
| 13 | + |
| 14 | +### Dijkstra's Algorithm – Node Labeling Process |
| 15 | + |
| 16 | +- **Node labeling** is the process of assigning values to nodes to represent the shortest known distance from the source node at each step of the algorithm. |
| 17 | +- At each iteration, nodes are divided into two sets: |
| 18 | + - **Labeled nodes (closed):** Nodes for which the shortest path from the source has been definitively found. |
| 19 | + - **Unlabeled nodes (open):** Nodes for which the shortest path is still being determined. |
| 20 | + |
| 21 | + |
| 22 | +#### Steps: |
| 23 | + |
| 24 | +1. **Initialization:** |
| 25 | + - Set \$ R = \{\} \$ (the set of labeled nodes is empty). |
| 26 | + - Set \$ NR = \{1, 2, 3, ..., n\} \$ (all nodes are initially unlabeled). |
| 27 | + - Assign 0 to the source node and ∞ to all others. |
| 28 | +2. **While \$ NR \neq \emptyset \$:** |
| 29 | + - Select the unlabeled node with the smallest value (node \$ k \$). |
| 30 | + - Move node \$ k \$ to the set of labeled nodes \$ R \$. |
| 31 | + - For each unlabeled successor node \$ j \$ of \$ k \$: |
| 32 | + - Add the value of node \$ k \$ to the cost of the arc from \$ k \$ to \$ j \$. |
| 33 | + - If this new value is less than the current value of node \$ j \$, update node \$ j \$ with the new value and set \$ k \$ as its predecessor. |
| 34 | + |
| 35 | +#### Importance of "Where I Came From" and "Where I Am": |
| 36 | + |
| 37 | +- **Where I came from:** In the tableau, the rows indicate the predecessor node, which is crucial for reconstructing the shortest path at the end. |
| 38 | +- **Where I am:** The columns represent the current node being evaluated in each iteration. |
| 39 | + |
| 40 | +--- |
| 41 | + |
| 42 | +### Step-by-Step Tableaus |
| 43 | + |
| 44 | +| 1* | 2* | 3* | 4* | 5* | 6 | 7* | 8* | 9* | |
| 45 | +| :-- | :-- | :-- | :-- | :-- | :-- | :-- | :-- | :-- | |
| 46 | +| 0 | ∞ | ∞ | ∞ | ∞ | ∞ | ∞ | ∞ | ∞ | |
| 47 | +| - | (1, 11) | (1, 9) | ∞ | ∞ | ∞ | ∞ | ∞ | ∞ | |
| 48 | +| - | (1, 11) | - | (3, 17) | (3, 15) | ∞ | ∞ | ∞ | ∞ | |
| 49 | +| - | - | - | (2, 15) | (3, 15) | ∞ | ∞ | ∞ | ∞ | |
| 50 | +| - | - | - | - | (3, 15) | (4, 21) | (4, 21) | (5, 19) | ∞ | |
| 51 | +| - | - | - | - | - | (4, 21) | (4, 20) | (5, 19) | (8, 25) | |
| 52 | +| - | - | - | - | - | (4, 21) | (4, 20) | - | (7, 24) | |
| 53 | + |
| 54 | +**Minimum Path:** |
| 55 | +1 → 2 → 4 → 7 → 9 = 24 |
| 56 | + |
| 57 | +--- |
| 58 | + |
| 59 | +### Summary |
| 60 | + |
| 61 | +- Here is your translation in English:- |
| 62 | + |
| 63 | +**Node labeling** is a fundamental part of Dijkstra's algorithm, systematically updating the shortest distances and predecessors for each node. |
| 64 | +- The tableau tracks, for each node, both the current shortest distance and the node from which that distance was reached. |
| 65 | +- At the end, by tracing back from the destination node using the predecessors, you reconstruct the shortest path. |
| 66 | + |
| 67 | + |
| 68 | + |
0 commit comments