concept distance in category algorithms

This is an excerpt from Manning's book Algorithms and Data Structures in Action.
But let’s see each operation in details, in table 2.4.
Anyway, for the moment we can imagine to restrict to this ideal situation; why is that? Well, because it makes our job easier: if all blocks are the same, and can be approximated with squares (or rectangles whose sides’ proportions are close to squares’), then we don’t have to worry about real distances, we can just count the number of blocks traveled to compute the length of a route; and the problem would be trivial to solve… if it wasn’t for one-way roads! Once we have a minimum viable solution working for this simplified scenario, we can think about developing it to cover more life-like situations.
Figure 14.10 Building a graph on the map in figure 14.8. We added a vertex to each road intersection (some vertices are however omitted for better readability) and edges connect adjacent intersections connected by a one-way road (two-way roads are modeled with a couple of edges).
![]()
Figure 14.10 shows the graph that can be built over the map shown in figure 14.9, where we added a vertex at each road intersection, and an edge going from vertex v to vertex u means that from the intersection modeled with v to the one modeled with u, there is a road that can be traveled in that direction (and not necessarily in the opposite one, from u to v).
14.3.2 Breadth First Search
Listing 14.2 shows the pseudo-code for Breadth First Search (BFS), whose goal, as the name suggests, is to widen the search as much as possible, keeping a perimeter of already visited vertices, and expanding this perimeter to the neighboring vertices: this is shown in figure 14.11, where the graph in figure 14.6.C is used to demonstrate the first few steps of this algorithm.
Listing 14.2 The bfs method
function bfs(graph, start, isGoal) #1 queue ← new Queue() #2 queue.insert(start) #3 distances ← new HashTable() #4 parents ← new HashTable() #5 for v in graph.vertices do #6 distances[v] ← inf parents[v] ← null distances[start] ← 0 #7 while not queue.empty() do #8 v ← queue.dequeue() #9 if isGoal(v) then #10 return (v, parents) for e in graph.adjacencyList[v] do #11 u ← e.dest if distances[u] == inf then #12 distances[u] ← distances[v] + 1 #13 parents[u] ← v queue.enqueue(u) return (null, parents) #14#1 Method bfs takes a graph, a starting point vertex, and a predicate (isGoal) that takes a vertex and returns true if the goal of the search is reached. Method bfs returns a pair with the goal vertex, and a dictionary encoding the shortest paths.