Chapter 10. Fundamental Network Algorithms. M. E. J. Newman. May 6, M. E. J. Newman Chapter 10 May 6, / 33

Similar documents
Shortest Paths. CSE 373 Data Structures Lecture 21

Algorithm Design (8) Graph Algorithms 1/2

CSE 100: GRAPH ALGORITHMS

Graphs. The ultimate data structure. graphs 1

CS420/520 Algorithm Analysis Spring 2009 Lecture 14

CS 3410 Ch 14 Graphs and Paths

COMP 182: Algorithmic Thinking Prim and Dijkstra: Efficiency and Correctness

Graphs. The ultimate data structure. graphs 1

Graph definitions. There are two kinds of graphs: directed graphs (sometimes called digraphs) and undirected graphs. An undirected graph

Design and Analysis of Algorithms

Design and Analysis of Algorithms

CS 161 Lecture 11 BFS, Dijkstra s algorithm Jessica Su (some parts copied from CLRS) 1 Review

2. True or false: even though BFS and DFS have the same space complexity, they do not always have the same worst case asymptotic time complexity.

Shortest Path Problem

CMPSC 250 Analysis of Algorithms Spring 2018 Dr. Aravind Mohan Shortest Paths April 16, 2018

Computer Networks. Routing

Dijkstra s Algorithm Last time we saw two methods to solve the all-pairs shortest path problem: Min-plus matrix powering in O(n 3 log n) time and the

CS 310 Advanced Data Structures and Algorithms

Notes on Minimum Spanning Trees. Red Rule: Given a cycle containing no red edges, select a maximum uncolored edge on the cycle, and color it red.

Theory of Computing. Lecture 4/5 MAS 714 Hartmut Klauck

Lecture 3: Graphs and flows

Graphs & Digraphs Tuesday, November 06, 2007

Solutions to relevant spring 2000 exam problems

Algorithm Analysis Graph algorithm. Chung-Ang University, Jaesung Lee

Graphs. Tessema M. Mengistu Department of Computer Science Southern Illinois University Carbondale Room - Faner 3131

TELCOM2125: Network Science and Analysis

CSE 417: Algorithms and Computational Complexity. 3.1 Basic Definitions and Applications. Goals. Chapter 3. Winter 2012 Graphs and Graph Algorithms

Introduction to Algorithms / Algorithms I Lecturer: Michael Dinitz Topic: Shortest Paths Date: 10/13/15

V2: Measures and Metrics (II)

Shortest path problems

Dr. Amotz Bar-Noy s Compendium of Algorithms Problems. Problems, Hints, and Solutions

Figure 1: A directed graph.

CS 512: Comments on Graph Search 16:198:512 Instructor: Wes Cowan

1 Shortest Paths. 1.1 Breadth First Search (BFS) CS 124 Section #3 Shortest Paths and MSTs 2/13/2018

Dijkstra s Shortest Path Algorithm

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer)

Single Source Shortest Path (SSSP) Problem

Fundamental Algorithms

Solutions for Operations Research Final Exam

Introduction To Graphs and Networks. Fall 2013 Carola Wenk

3.1 Basic Definitions and Applications

Week 11: Minimum Spanning trees

Centralities (4) By: Ralucca Gera, NPS. Excellence Through Knowledge

CSE 101. Algorithm Design and Analysis Miles Jones Office 4208 CSE Building Lecture 6: BFS and Dijkstra s

EE266 Homework 8 Solutions

Direct Addressing Hash table: Collision resolution how handle collisions Hash Functions:

Single Source Shortest Path

Graph Search. Adnan Aziz

Mining Social Network Graphs

Algorithm Design and Analysis

Prelim 2 Solution. CS 2110, April 26, 2016, 7:30 PM

The Shortest Path Problem. The Shortest Path Problem. Mathematical Model. Integer Programming Formulation

Algorithms (V) Path in Graphs. Guoqiang Li. School of Software, Shanghai Jiao Tong University

Advanced Algorithms Class Notes for Monday, October 23, 2012 Min Ye, Mingfu Shao, and Bernard Moret

Source. Sink. Chapter 10: Iterative Programming Maximum Flow Problem. CmSc250 Intro to Algorithms

CISC-235* Test #3 March 19, 2018

Priority Queues. 1 Introduction. 2 Naïve Implementations. CSci 335 Software Design and Analysis III Chapter 6 Priority Queues. Prof.

INDIAN STATISTICAL INSTITUTE

CS473-Algorithms I. Lecture 13-A. Graphs. Cevdet Aykanat - Bilkent University Computer Engineering Department

Algorithms: Lecture 10. Chalmers University of Technology

DESIGN AND ANALYSIS OF ALGORITHMS GREEDY METHOD

Evolutionary tree reconstruction (Chapter 10)

Elementary Graph Algorithms: Summary. Algorithms. CmSc250 Intro to Algorithms

1 Shortest Paths. 1.1 Breadth First Search (BFS) CS 124 Section #3 Shortest Paths and MSTs 2/13/2018

Prelim 2. CS 2110, November 20, 2014, 7:30 PM Extra Total Question True/False Short Answer

UNIT 4 Branch and Bound

CS 170 Spring 2000 Solutions and grading standards for exam 1 Clancy

TA: Jade Cheng ICS 241 Recitation Lecture Note #9 October 23, 2009

Practice Problems for the Final

Path Length. 2) Verification of the Algorithm and Code

W4231: Analysis of Algorithms

Centrality Book. cohesion.

Load Balancing and Termination Detection

Computational Geometry

CS350: Data Structures Dijkstra s Shortest Path Alg.

Dijkstra s Algorithm and Priority Queue Implementations. CSE 101: Design and Analysis of Algorithms Lecture 5

Lecture 9 Graph Traversal

CPSC 320 Sample Solution, Playing with Graphs!

Goals! CSE 417: Algorithms and Computational Complexity!

Definition For vertices u, v V (G), the distance from u to v, denoted d(u, v), in G is the length of a shortest u, v-path. 1

CSE 100: GRAPH ALGORITHMS

CSE 373: Data Structures and Algorithms

EE365 Homework 8. (a) A key step in Dijkstra s algorithm is computing the neighbors of a vertex x:

SELF-BALANCING SEARCH TREES. Chapter 11

The Simplex Algorithm

Info 2950, Lecture 16

1 i n (p i + r n i ) (Note that by allowing i to be n, we handle the case where the rod is not cut at all.)

CSC 421: Algorithm Design & Analysis. Spring 2015

Prelim 2 Solution. CS 2110, April 26, 2016, 5:30 PM

Line segment intersection. Family of intersection problems

Graphs. Terminology. Graphs & Breadth First Search (BFS) Extremely useful tool in modeling problems. Consist of: Vertices Edges

6. Advanced Topics in Computability

1 Homophily and assortative mixing

TELCOM2125: Network Science and Analysis

Content. 1 Algorithms. 2 Assignment and Knapsack problem 3 Bin Packing. 4 Scheduling

Cuckoo Hashing for Undergraduates

TIE Graph algorithms

d. Solution coming soon. 6. Directed Graphs

2.1 Greedy Algorithms. 2.2 Minimum Spanning Trees. CS125 Lecture 2 Fall 2016

Lecture Notes. char myarray [ ] = {0, 0, 0, 0, 0 } ; The memory diagram associated with the array can be drawn like this

Transcription:

Chapter 10 Fundamental Network Algorithms M. E. J. Newman May 6, 2015 M. E. J. Newman Chapter 10 May 6, 2015 1 / 33

Table of Contents 1 Algorithms for Degrees and Degree Distributions Degree-Degree Correlation 2 Clustering Coefficient 3 Shortest Paths Breadth-First Search Variants of BFS Finding Shortest Paths 4 Betweenness Centrality 5 Shortest Paths in Networks with Varying Edge Lengths M. E. J. Newman Chapter 10 May 6, 2015 2 / 33

Algorithms for Degrees and Degree Distributions Degree Degree of a vertex is one of the most fundamental and important of network quantities. If we use an adjacency list, we normally maintain an array containing the degree of each vertex. Computational complexity to find a degree of a vertex: O(1). If we use an adjacency matrix, the calculation takes time O(N). If one needed to find the degrees of vertices frequently during a large calculation using an adjacency matrix, it would be better to calculate the degree of each vertex once and for all and store the results for later easy retrieval in a separate array. M. E. J. Newman Chapter 10 May 6, 2015 3 / 33

Algorithms for Degrees and Degree Distributions Degree Distributions Degree distributions are of considerable interest in the study of networks for the effect they have on network structure and processes on networks. Calculating the degree distribution, p k is straightforward: Once we have the degrees of all vertices, we make a histogram of them by creating an array to sture the number of vertices of each degree up to the network maximum. Let ndegree[i] be the ithe element of the array. Initially set ndegree[i]=0 for all i. Running through the vertices in turn, if the degree of ith node is k i then increase ndgree[k i] by one. Normalize each elements, ndegree[i], by dividing N. Computational complexity: O(N). Cumulative degree distribution: P k P k = p k = p k 1 + k k =k 1 p k = P k 1 p k 1. (1) M. E. J. Newman Chapter 10 May 6, 2015 4 / 33

Algorithms for Degrees and Degree Distributions Degree-Degree Correlation Correlation Coefficient Definition r = ij (A ij k i k j /2m)k i k j ij (k iδ ij k i k j /2m)k i k j (2) Rewrite the equation as where and S e = ij S 1 = i k i, r = S 1S e S2 2 S 1 S 3 S2 2, (3) A ij k i k j = 2 S 2 = i edges (i,j) k 2 i, S 3 = i k i k j, (4) k 3 i (5) Use Eq. (3) for calculating correlation coefficient with complexity O(m + N). M. E. J. Newman Chapter 10 May 6, 2015 5 / 33

Clustering Coefficient Clustering Coefficient Local Clustering Coefficient C i = [# of pairs of neighbors of i that are connected] [# of pairs of neighbors of i] (6) For each pairs of neighbor of i, (j, l) (j < l), we determine whether an edge exists between them. The details of algorithm depends on the stored network data format. Then divide by k i (k i 1)/2. M. E. J. Newman Chapter 10 May 6, 2015 6 / 33

Clustering Coefficient Clustering Coefficients Global Clustering Coefficient C i = [# of triangles] 3 [# of connected triples] (7) connected triples: three vertices uvw with edges (u, v) and (v, w). (The edge (u, v) can be present or not). For every vertex each pair of neighbors (j, l) with j < l and find whether they are connected by an edge. Add up the total number of such edges. Divide by the number of connected triples, which is i k i(k i 1)/2. ( Unfortunately, the complexity is O n [ k 2 k 2 k ]). 1 For highly skewed p k, k 2 becomes large or diverges. Matrix/list hybrid structure can slightly improve the performance. M. E. J. Newman Chapter 10 May 6, 2015 7 / 33

Shortest Paths Breadth-First Search Breadth-First Search (BFS) Known as the burning algorithm in physics. A single run of the BFS algorithm finds the shortest (geodesic) distance from a single source vertex s to every other vertex in the same component of the network as s. Even when we want to know the shortest distance between a single pair of vertices s and t, use the BFS algorithm to calculate shortest distance from s to every other vertex and then throwing away all of the results except for the one we want. The BFS can be also applied to the directed networks. M. E. J. Newman Chapter 10 May 6, 2015 8 / 33

Shortest Paths Breadth-First Search Description of the Algorithm BFS algorithm finds the shortest distance from a given starting vertex s to every other vertex in the same component as s. Initially, we set the distance to s be 0. Find all the neighbors of s, and set the distance to be 1. Then find all the neighbors of those vertices. If those neighbors are not already visited, set the distance to be 2. Repeat the procedure. M. E. J. Newman Chapter 10 May 6, 2015 9 / 33

Shortest Paths Breadth-First Search A Naive Implementation: Complexity O(m + N log N) Create an array of N elements to store the distance of each vertex from the source vertex s. Initially set the distance to s from itself to be zero All other vertice have unknown distance, for example, 1, or some similar value that could not occur in reality. We also introduce a distance variable d to keep track of where we are in the BFS process. Set d = 0 as its initial value. 1. Find all vertices that are distance d from s, by going through the distance array, element by element. 2. Find all the neighbors of those vertices and check each one to see if its distance from s is unknown. 3. If the number of neighbors with unknown distance is zero, the algorithm is over. Otherwise, if the number of neighbors with unknown distance is non-zero, set the distance of each of those neighbors to d + 1. 4. Increase d by 1. 5. Repeat from step 1. M. E. J. Newman Chapter 10 May 6, 2015 10 / 33

Shortest Paths Breadth-First Search A Better Implementation The time-consuming part of the naive implementation is step 1. We go through the list of distances of size N to find vertices that are distance d from the starting vertex s. Only the small fraction of the list will be at distance d waste a lot of time. Strategy: Make a list of vertices at distance d. Then we wouldn t have to search through the whole network for vertices at distance d + 1. Use the fist-in/first-out buffer or queue. Nothing more than an array of N elements. In the array, a list of labels of vertices are stored. On each sweep of the algorithm, we read the vertices with distance d from the list. Use these to find the vertices with distance d + 1. Add those vertices with distance d + 1 to the list. Repeat the procedure. Introduce the read and write pointers, which are the simple integer variables. M. E. J. Newman Chapter 10 May 6, 2015 11 / 33

Shortest Paths Breadth-First Search A Better Implementation Algorithm 0. Use two arrays of N elements. one for the queue. one for the distance from s to each vertex. 1. Place the label of the source vertex s in the first element of the queue. Set the read pointer to point the first element. Set the write pointer to point the second element, which is the first empty one. In the distance array, record the distance of vertex s from itself as as being zero. Set the distances of all other vertices to be unknown (e.g. 1). M. E. J. Newman Chapter 10 May 6, 2015 12 / 33

Shortest Paths Breadth-First Search A Better Implementation Algorithm 2. If the read and the write pointers are pointing to the same element of the queue then the algorithm is finished. Otherwise, read the vertex label from the element pointed to by the read pointer and increases that pointer by one. 3. Find the distance d for that vertex by looking in the distance array. 4. Go through each neighboring vertex in turn and look up its distance in the distance array. If it has a known distance, leave it alone. If it has an unknown distance, assign it distance d + 1, store its label in the queue array in the element pointed to by the write pointer, and increase the write pointer by one. M. E. J. Newman Chapter 10 May 6, 2015 13 / 33

Shortest Paths Breadth-First Search A Better Implementation Algorithm 5. Repeat from step 2. Complexity: O(m + N) or on sparse networks, O(N). M. E. J. Newman Chapter 10 May 6, 2015 14 / 33

Shortest Paths Variants of BFS Variants of BFS The shortest distance between a specific pair of nodes Apply BFS from a source vertex s, and stop the algorithm if a target t is found. The shortest distance between every pair of nodes Apply BFS starting at each vertex in the network in turn. Complexity: O(N(m + N)) or O(N 2 ) on a sparse network. Identify the component Apply BFS from a source s. Size of the component is the number of vertices with known distance. Closeness centrality Apply BFS from a source vertex s. Add the distances of all nodes with known distance and divide by the size of the component and take the inverse. M. E. J. Newman Chapter 10 May 6, 2015 15 / 33

Shortest Paths Finding Shortest Paths Finding Shortest Paths BFS algorithm so far does not tell us the particular path or paths by which that shortest distance is achieved. With only relatively small modification of the algorithm gives the paths as well. Introduce another directed network on top of the original one. The directed network represents the shortest paths shortest path tree. In general it is a directed acyclic graph, not a tree. M. E. J. Newman Chapter 10 May 6, 2015 16 / 33

Shortest Paths Finding Shortest Paths Finding Shortest Paths Idea At start of BFS algorithm, create an extra network, which will become the shortest path tree. The extra network has the same number N of vertices as the original network. The extra network has the same vertex labels, but with no edges at all. Start BFS algorithm from the specified source vertex s. At each time, if the neighbor j of some vertex i has a distance unknown, we assign j a distance, store it in the queue, and add a directed edge to the shortest path tree from j to i. This directed edge tells us that we found j by following a path from its neighbor i. By following succession of these directed edge, we eventually get all the way back to s, and so we can reconstruct entire shortest path between (j, s). M. E. J. Newman Chapter 10 May 6, 2015 17 / 33

Shortest Paths Finding Shortest Paths Finding Shortest Paths Problem This algorithm finds only one shortest path to each vertex from s. In general, a pair of vertices can have more than one shortest paths between them. This occurs if there is a vertex j somewhere along that path, say at distance d + 1 from s, that has more than one neighbor at distance d. We can resolve the problem by adding more than one directed edge from j to each of the relevant neighbors. M. E. J. Newman Chapter 10 May 6, 2015 18 / 33

Shortest Paths Finding Shortest Paths Finding Shortest Paths Modified Algorithm We perform the BFS starting from s. Add directed deges from newly found vertices to their neighbor. If in the process of examining the neighbor of a vertex i that has distance d from s, we discover a neighbor j that already has a known distance d + 1, then add an extra directed edge to the shortest path tree from j to i. This makes the shortest path tree no longer a tree, but it s usually called as a tree. M. E. J. Newman Chapter 10 May 6, 2015 19 / 33

Betweenness Centrality Betweenness Centrality The betweenness centrality (BC) of vertex v is the number of geodesic paths between pairs of vertices s, t that pass through v. The simplest way: implement the definition of the measure directly: Use BFS to find the shortest path between s and t. Along that shortest paths, check the vertices it passes to see if the vertex v lies among them. Repeat the process for every distinct pair s, t, then count the total number of paths that pass through v. Complexity: O(N 2 (m + N)) or O(N 3 ) for sparse network. Should be improved. M. E. J. Newman Chapter 10 May 6, 2015 20 / 33

Betweenness Centrality Betweenness Centrality Improved Algorithm Make use of some of the results about BFS. For each s we use BFS to find shortest paths between s and all other nodes. Construct a shortest path tree. Use that tree to trace the paths from each node back to s. Count the number of paths that go through v. Repeat this calculation for all s. Complexity: O(N 2 log N). M. E. J. Newman Chapter 10 May 6, 2015 21 / 33

Betweenness Centrality Betweenness Centrality Further Improvement First consider the case when there is only a single shortest path. Find the leaves of the tree. Assign a score 1 to each of these leaves. This means that the only path to s that pass through these vertices is the one that starts there. Starting at the bottom of the tree we go upward, assigning to each vertex a score that is 1 plus the sum of the scores on the neighboring nodes immediately below it. This means that the number of paths through a node v is 1 for the path that starts at v plus the count of all paths that starts below v in the tree and hence have to pass through it. M. E. J. Newman Chapter 10 May 6, 2015 22 / 33

Betweenness Centrality Betweenness Centrality Further Improvement cont d When we have worked all the way up the tree in this manner and reaches s, the scores at each vertex are equal to the betweenness counts for path that end at s. Repeating the process for all s and summing the scores. The resulting score is the full betweenness score for all paths. In practice, this modified algorithm is accomplished by running through the vertices in order of decreasing distance from s. Use the queue. The algorithm involves running backwards through the list of vertices in the queue and calculating the number of paths through each nodes until the beginning of the queue is reached. Complexity: O(N(m + N)). M. E. J. Newman Chapter 10 May 6, 2015 23 / 33

Betweenness Centrality Betweenness Centrality More General Case When there is loops, it is convenient to think about the flow BC introduced by Freeman et al. Basic idea is that the multiple shortest paths between the same pair of vertices are given equal weights summing to 1. Ex]. for a vertex pair connected by three shortest paths, we give each path weight 1/3. To calculate the weights of the paths flowing through each vertex in a network, we have first to calculate the total number of shortest paths from each vertex to s. This is quite straightforward to do: The shortest paths from s to i must pass through one or more neighbor of i The total number of shortest paths to i is simply the sum of the numbers of shortest paths to each of those neighbors. M. E. J. Newman Chapter 10 May 6, 2015 24 / 33

Betweenness Centrality Betweenness Centrality Flow BC: Algorithm assigning weight Use the modified BFS. Suppose we are starting at s. 1. Assign vertex s distance zero, to indicate that it is zero steps from itself and set d = 0. Also assign s a weight w s = 1. 2. For each vertex i whose assigned distance is d, follow each attached edge to the vertex j at its other end and do one of the following three things: a) If j has not yet been assigned a distance, assign it distance d + 1 and weight w j = w i. b) If j has already assigned a distance and that distance is equal to d + 1, then the vertex s weight is increased by w i, that is w j w j + w i. c) If j has already been assigned a distance less than d + 1, do nothing. 3. Increase d by 1. 4. Repeat from step 2 until there are no vertices that have distance d. See the numbers at the left of each vertex (weight). M. E. J. Newman Chapter 10 May 6, 2015 25 / 33

Betweenness Centrality Betweenness Centrality Flow BC: Algorithm determining BC w i is the number of geodesic paths between s and i. If i and j are connected by a directed edge in the shortest path tree pointing from j to i, then the fraction of the paths to s that pass through (or starting at) j and that also pass through i is given by w i /w j. M. E. J. Newman Chapter 10 May 6, 2015 26 / 33

Betweenness Centrality Betweenness Centrality Flow BC: Algorithm determining BC To calculate the contribution to the betweenness from shortest paths starting at all vertices and ending at s, we need only carry out the following steps: 1. Find every leaf vertex t and assign it a score of x t = 1. 2. Starting at the bottom of the tree, work up towards s and assign to each vertex i a score x i = 1 + j xjwi/wj, where the sum is over the neighbors j immediately below vertex i. 3. Repeat from step 2 until s is reached. See the numbers at the right of each vertex. Complexity: O(N(N + m)) or O(N 2 ) for a sparse network. M. E. J. Newman Chapter 10 May 6, 2015 27 / 33

Shortest Paths in Networks with Varying Edge Lengths Shortest Paths in Networks with Varying Edge Lengths Weighted Networks: the traffic capacity of connections on the Internet frequencies of contacts between acquaintances in a social network In some cases the values on edges can be interpreted as lengths for edges. The length can be: real length such as the distances along roads in a road network or length like measures. Finding shortest path between two nodes taking the length of edges into account. finding the shortest driving route from A to B via a road network finding the route across the Internet to send a data packet to a specified destination in the shortest time. M. E. J. Newman Chapter 10 May 6, 2015 28 / 33

Shortest Paths in Networks with Varying Edge Lengths Shortest Paths in Networks with Varying Edge Lengths Problem: The shortest path across a network with edge length may not be the same as the shortest path in terms of number of edges. To solve the problem, introduce Dijkstra s algorithm (DA). DA works by keeping a record of the shortest distance it has found so far to each vertex and updating that record whenever a shorter one is found. M. E. J. Newman Chapter 10 May 6, 2015 29 / 33

Shortest Paths in Networks with Varying Edge Lengths Dijkstra s Algorithm Dijkstra s Algorithm Preliminary Procdures Start by creating an array of N elements to hold our current estimates of the distances from s to every vertex. At all time during the running of the algorithm these estimates are upper bounds on the true shortest distances. Initially, set the estimates of the distance from s to s to be zero. set the distance from s to every other node to be. Create another array of N elements. This is used to save the information whether we are certain that the distance we have to a given vertex is the smallest possible distance. Ex.) use 1s to indicate the distances we are sure about and 0s for the distances that are just our best current estimate. Initially, set all element of this array to be 0. M. E. J. Newman Chapter 10 May 6, 2015 30 / 33

Shortest Paths in Networks with Varying Edge Lengths Dijkstra s Algorithm Dijkstra s Algorithm Finding the Shortest Distances 1. Find the vertex v in the network that has the smallest estimated distance from s, i.e., the smallest distance about which we are not yet certain. 2. Mark this distance as being certain. 3. Calculate the distance from s via v to each of the neighbors of v by adding to v s distance the length of the edges connecting v to each neighbor. If any of the resulting distances is smaller than the current estimated distance to the same neighbor, the new distance replaces the older one. 4. Repeat from step 1 until the distance to all vertices are flagged as being certain Complexity: O(m + N 2 ) or O(m + N) with binary heap. Store the estimated distance in a binary heap. M. E. J. Newman Chapter 10 May 6, 2015 31 / 33

Shortest Paths in Networks with Varying Edge Lengths Dijkstra s Algorithm Dijkstra s Algorithm Why it works correctly? The crucial step is step 2. We declare the current smallest estimated distance to be certain. Consider a vertex v. Consider a hypothetical path from s is shorter than the current estimated distance recorded for v. Since the hypothetical path is shorter than the estimated distance to v, the distance along the path to each vertex in the path must be shorter than the estimated distance to v. Furthermore, there must exist somewhere along the path a pair of adjacent vertices x, y such that x s distance is known for certain and y s is not. Vertex x need not necessarily be distinct from s. M. E. J. Newman Chapter 10 May 6, 2015 32 / 33

Shortest Paths in Networks with Varying Edge Lengths Dijkstra s Algorithm Dijkstra s Algorithm Why it works correctly? But y must be distinct from v. If y and v were the same vertex, so that v was a neighbor of x, then we would already have found the shorter path to v when we explored the neighbor of x in step 3. WE accordingly have revised our estimate of v s distance downward. Since this hasn t happened, y and v must be distinct nodes. y s current estimated distance will be at most equal to its distance from s along the path because that distance is calculated in step 3. Since all distance along the path are necessarily less than the current estimated distance to v, y s estimated distance must be less than v s. Contradict the hypothesis that v is the vertex with the shortest estimated distance. Hence there is no path to vertex v with length less than v s current estimated distance, so we can safely mark that distance as being certain. M. E. J. Newman Chapter 10 May 6, 2015 33 / 33