1. Home
  2. Explore
  3. Computer Science
  4. Shortest-Path Algorithms

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Shortest-Path Algorithms

  • 58Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Search Foundations

Why is checking every possible route an impractical way to find the shortest route across a large road network?

58 questions

  1. 1

    Why is checking every possible route an impractical way to find the shortest route across a large road network?

    Model answer

    A network with over 64 million intersections can have roughly 1022010^{220}10220 possible routes. Even checking a billion routes per second would take over 1020010^{200}10200 years.

    Explanation

    The number of possible routes grows so enormously that exhaustive search is infeasible, even with very fast computers.

  2. 2

    How can a road network be represented as a graph for pathfinding?

    Model answer

    Intersections or cities are represented as nodes, and roads connecting them are represented as edges.

    Explanation

    This representation lets a pathfinding algorithm search among connected locations.

  3. 3

    How does Breadth-First Search find a path in an unweighted graph?

    Model answer

    It explores all nodes one step from the source, then all nodes two steps away, and continues outward until it reaches the target.

    Explanation

    The search expands in layers based on the number of edges from the source.

  4. 4

    Why does Breadth-First Search find the fewest-edge path in an unweighted graph?

    Model answer

    It checks paths in order of increasing number of edges, so the first time it reaches the target, no path with fewer edges can exist.

    Explanation

    For example, if a target is first reached in five steps, the search has already checked all paths of four steps or fewer.

  5. 5

    Why is ordinary Breadth-First Search unsuitable when roads have different lengths?

    Model answer

    It treats every edge as having the same length, so the path with the fewest edges may not have the smallest total distance.

    Explanation

    A route with fewer roads can still be longer if its roads have greater weights.

  6. 6

    What does an edge weight represent in a weighted road graph?

    Model answer

    An edge weight represents a value associated with traversing a road, such as its distance or travel time.

    Explanation

    The route's total cost is calculated from the weights of its edges.

  7. 7

    Why do navigation systems need algorithms that do more than simply find a route?

    Model answer

    They must find routes quickly despite the enormous number of possible paths and the large size of road networks.

    Explanation

    A route-finding method must be efficient enough to handle many users and large graphs.

  8. 8

    Beyond road navigation, name two kinds of systems that can use pathfinding algorithms.

    Model answer

    Robots and video-game characters can use pathfinding to navigate mazes, obstacle courses, or other environments.

    Explanation

    These systems face the same general problem of finding a route through a network of possible movements.

  9. 9

    How does Dijkstra's algorithm initialize the costs of nodes?

    Model answer

    It assigns the source node a cost of zero and every other node a cost of infinity.

    Explanation

    Initially, the source is known to be zero distance away, while no route to other nodes has yet been established.

  10. 10

    What does a node's cost represent in Dijkstra's algorithm?

    Model answer

    It represents the length of the shortest route from the source to that node found so far.

    Explanation

    The cost is updated whenever the algorithm finds a cheaper route to the node.

  11. 11

    How does Dijkstra's algorithm update a neighboring node's cost?

    Model answer

    It adds the current node's cost to the connecting edge's weight and updates the neighbor if this total is less than the neighbor's current cost.

    Explanation

    This comparison is called relaxing the edge: the newly found route replaces the recorded cost only if it is shorter.

  12. 12

    Which unexplored node does Dijkstra's algorithm explore next?

    Model answer

    It explores the unexplored node with the lowest current cost.

    Explanation

    This makes the explored region grow in order of increasing path cost from the source.

  13. 13

    Why might Dijkstra's algorithm update a node's cost more than once?

    Model answer

    It may first discover a relatively expensive route to a node and later find a cheaper route through another node.

    Explanation

    For instance, a route with total cost seven can be replaced when a route with total cost six is discovered.

  14. 14

    When can Dijkstra's algorithm be certain that a reached target has the shortest path?

    Model answer

    It can be certain when the target is the lowest-cost unexplored node and is selected for exploration.

    Explanation

    By then, every route with a lower cost has been explored, and none has produced a cheaper path to the target.

  15. 15

    Why does Dijkstra's algorithm explore nodes in increasing cost order?

    Model answer

    Exploring in increasing cost order ensures that all paths cheaper than the next selected cost have already been considered.

    Explanation

    If the lowest-cost unexplored node has cost 18, for example, every path with cost below 18 has already been explored.

  16. 16

    How does Dijkstra's algorithm differ from Breadth-First Search?

    Model answer

    Breadth-First Search expands by number of edges, whereas Dijkstra's algorithm expands by accumulated edge weight.

    Explanation

    Dijkstra's method therefore handles graphs in which edges have different costs.

  17. 17

    What was the purpose of Dijkstra's original shortest-path demonstration on the ARMAC computer?

    Model answer

    It demonstrated computing power through an understandable problem: finding the shortest route between two towns.

    Explanation

    The route could be printed town by town, making the result easy for a general audience to understand.

  18. 18

    What is a heuristic in A-star search, and how is it used?

    Model answer

    A heuristic estimates the remaining cost from a node to the target. A-star uses it alongside the cost already accumulated to prioritize which nodes to explore.

    Explanation

    In the described version, nodes are ordered using their known route cost plus their estimated straight-line distance to the target.

  19. 19

    How does straight-line distance help A-star search a road graph?

    Model answer

    It estimates how close each node is to the target, so A-star can prioritize nodes that appear to lead in the target's direction.

    Explanation

    The estimate can be calculated from a node's latitude and longitude.

  20. 20

    How can A-star's distance heuristic be visualized as a three-dimensional landscape?

    Model answer

    Each node can be raised to a height representing its straight-line distance from the target; nodes farther away are higher.

    Explanation

    A-star's heuristic penalizes movement toward higher points, discouraging exploration in directions away from the target.

  21. 21

    How does A-star's search frontier differ from Dijkstra's when the heuristic points toward the target?

    Model answer

    Dijkstra's frontier spreads outward in all directions by cost, while A-star prioritizes nodes that are closer to the target.

    Explanation

    This directional guidance can reduce the number of nodes explored.

  22. 22

    What is the effect of making A-star's heuristic penalty steeper?

    Model answer

    A steeper penalty makes A-star spread out less and focus more aggressively toward the target.

    Explanation

    Changing the heuristic changes how strongly the search favors estimated progress toward the goal.

  23. 23

    How can A-star be adapted to find a route minimizing travel time rather than geographic distance?

    Model answer

    Divide the straight-line distance to the target by the maximum permitted speed to estimate a minimum remaining travel time.

    Explanation

    This estimate is an underestimate because actual roads and routes may require more time than the direct-distance estimate.

  24. 24

    Why may A-star perform less advantageously for travel-time routing than for distance routing?

    Model answer

    Its time heuristic can require costly calculations, including square roots, and may reduce the number of explored nodes by too little to offset that overhead.

    Explanation

    In the described comparison, A-star explored fewer nodes for travel time, but not enough to outperform a well-tuned Dijkstra search.

  25. 25

    What does the comparison between A-star and Dijkstra show about the effect of the routing objective?

    Model answer

    A-star can substantially reduce the search for shortest geographic distance, but its advantage can shrink or disappear when optimizing travel time.

    Explanation

    On the New York City graph, Dijkstra explored about 9.5 times as many nodes as A-star for distance; for travel time, A-star's node count tripled while Dijkstra's increased by only 10%.

  26. 26

    What is bidirectional Dijkstra search?

    Model answer

    It runs one Dijkstra search from the source and another from the target, continuing until the two search frontiers meet.

    Explanation

    Searching from both ends can reduce how far each individual search must expand.

  27. 27

    Why can bidirectional search reduce the explored area compared with a single search?

    Model answer

    If the source and target are far apart, each search only needs to cover roughly half the distance before the frontiers meet.

    Explanation

    In an idealized geometric graph, this can reduce the total covered area to about half of a single search's area.

  28. 28

    What was the result of the described bidirectional Dijkstra search from Carnegie Hall to Wall Street?

    Model answer

    It explored a little over 2,600 nodes, compared with over 7,200 for a one-directional Dijkstra search.

    Explanation

    This amounted to close to a threefold improvement in the number of explored nodes for that example.

  29. 29

    Why do Dijkstra and A-star fail to fully exploit the structure of road networks?

    Model answer

    They do not inherently understand that roads have a hierarchy, such as local streets leading to highways for long-distance travel.

    Explanation

    Without that knowledge, they may treat an unimportant local road as equally worth exploring as a major highway when costs are similar.

  30. 30

    How did early in-car GPS systems use road hierarchies to narrow a search?

    Model answer

    They assigned roads categories such as narrow roads, major local roads, and express highways, then searched progressively higher categories if needed.

    Explanation

    Surveyed road features were used to classify roads, and bidirectional Dijkstra searched within expanding candidate areas at successive hierarchy levels.

  31. 31

    What is the risk of using a candidate area that is too small in a hierarchical routing method?

    Model answer

    The search may miss a better route using roads outside the area and return a longer route, such as a highway route when local roads would be shorter.

    Explanation

    An overly restricted search can exclude the true shortest path.

  32. 32

    What is the trade-off in choosing a very large candidate area for hierarchical search?

    Model answer

    A large area is more likely to contain the shortest path, but searching it may become little better than running Dijkstra over the graph.

    Explanation

    Restricting the area improves speed, while expanding it improves the chance of finding the optimal route.

  33. 33

    What two goals must a routing algorithm balance when using preprocessing?

    Model answer

    It should make queries fast while keeping preprocessing time and storage requirements manageable.

    Explanation

    A complete lookup table could answer queries extremely quickly, but constructing and maintaining it would be impractical; Dijkstra needs no preprocessing but can be slow.

  34. 34

    Why would a precomputed table of every shortest route be impractical for a large road network?

    Model answer

    Building it would require running a search from every intersection, and storing the results would require more than eight petabytes in the example.

    Explanation

    For a network with 64 million intersections, the calculations would take over a decade on a single core, and road changes or traffic updates would require updates to the stored results.

  35. 35

    What is the central idea of a contraction hierarchy?

    Model answer

    Preprocess the graph by ranking nodes by importance, then answer queries with bidirectional Dijkstra searches that move only upward through the hierarchy.

    Explanation

    A useful hierarchy limits the query search space while shortcuts preserve shortest routes that would otherwise be missed.

  36. 36

    What makes a node important in a road-network hierarchy?

    Model answer

    A node is important when many shortest paths must pass through it, especially when it forms a bottleneck separating large parts of the network.

    Explanation

    A bridge between two similarly sized regions can be highly important because many trips between those regions use it.

  37. 37

    What is a small cut of nodes, and why is it useful for ranking nodes?

    Model answer

    A small cut is a small set of nodes whose removal separates a graph into parts. Such a set can be important if it divides the graph roughly in half.

    Explanation

    Nodes in the cut act as bottlenecks for trips between the separated regions.

  38. 38

    How does nested dissection build a node hierarchy?

    Model answer

    It finds small cuts that divide the graph, ranks those nodes highly, and recursively finds cuts within the resulting subgraphs.

    Explanation

    The process continues until all nodes have been ranked.

  39. 39

    Why might bridges over the Mississippi River receive high importance ranks in a North American road graph?

    Model answer

    They are bottlenecks for many routes connecting the eastern and western parts of the network.

    Explanation

    In the described graph, 102 nodes formed a cut through which east-to-west trips had to pass.

  40. 40

    How does a contraction-hierarchy query use node ranks?

    Model answer

    It runs a Dijkstra search from each endpoint, allowing each search to move only toward higher-ranked nodes, so the searches can meet near the top of the hierarchy.

    Explanation

    The bidirectional search is essential because a one-directional upward search can become stuck for many source-target pairs.

  41. 41

    Why can an upward-only search miss the shortest path before shortcuts are added?

    Model answer

    The shortest route may pass through a lower-ranked node that the upward-only search is not allowed to visit.

    Explanation

    A search restricted to increasing ranks could otherwise return a longer path that uses only higher-ranked nodes.

  42. 42

    What is a lower triangle in the shortcut-building process?

    Model answer

    It occurs when a low-ranked node connects to at least two higher-ranked nodes.

    Explanation

    A path through that lower-ranked node may be the shortest connection between the higher-ranked nodes, even though an upward-only query cannot search through it.

  43. 43

    How does a shortcut preserve a route that passes through a lower-ranked node?

    Model answer

    The algorithm adds an edge between the connected higher-ranked nodes whose weight represents the cost of the path through the lower-ranked node.

    Explanation

    A shortcut does not represent a real road; it records the cost of a route in the original graph.

  44. 44

    What should happen if a shortcut competes with an existing edge or another shortcut?

    Model answer

    The connection should represent the path with the minimum cost among the available alternatives.

    Explanation

    Keeping the minimum-cost connection ensures that a more expensive route does not replace a better one.

  45. 45

    Why are shortcuts added from the lowest-ranked nodes upward?

    Model answer

    Adding them bottom-up preserves necessary shortest paths through lower-ranked nodes while allowing the query to ignore those nodes.

    Explanation

    The process creates shortcuts only when needed to maintain routes that the upward-only search would otherwise overlook.

  46. 46

    Why can a contraction hierarchy use different valid node rankings without losing shortest-path correctness?

    Model answer

    Shortcuts can restore shortest routes overlooked by a ranking, so several rankings can still return correct shortest paths.

    Explanation

    The ranking affects efficiency rather than correctness, provided the necessary shortcuts are constructed.

  47. 47

    How can a poor node ranking reduce the efficiency of a contraction hierarchy?

    Model answer

    It can force queries to explore many nodes or require too many shortcuts, increasing search time or graph size.

    Explanation

    For a line of nodes, contracting from one end to the other may require no shortcuts but still make an end-to-end query examine every node.

  48. 48

    What trade-off should be considered when choosing a node ordering?

    Model answer

    The ordering should balance the number of shortcuts added against how much it reduces query search.

    Explanation

    A ranking with very few shortcuts may still produce slow queries, while one that speeds queries substantially may enlarge the graph considerably.

  49. 49

    What are the three phases of a customizable contraction hierarchy?

    Model answer

    The phases are ordering the nodes and adding shortcuts, calculating shortcut weights, and searching for a route.

    Explanation

    The first phase establishes the hierarchy, the second adapts its weights to the graph's current costs, and the third answers a query.

  50. 50

    When does the node-ordering and shortcut-creation phase of a customizable contraction hierarchy need to be repeated?

    Model answer

    It needs to be repeated when the graph's structure changes, such as when a road closes or a new bridge opens.

    Explanation

    This is the most expensive preprocessing phase, but it does not need to be repeated for ordinary traffic-weight updates.

  51. 51

    Why must shortcut weights be recalculated when traffic conditions change?

    Model answer

    Traffic changes affect the costs of routes represented by shortcuts, so their weights must reflect the updated costs.

    Explanation

    The node ordering may remain the same while the weights used for travel-time routing change.

  52. 52

    What does the term “customizable” refer to in a customizable contraction hierarchy?

    Model answer

    It refers to recalculating shortcut weights to adapt the preprocessed hierarchy to changing edge costs, such as traffic updates.

    Explanation

    The hierarchy can be reused when costs change, provided the graph's structure has not changed.

  53. 53

    How did the described customizable contraction hierarchy compare with Dijkstra on the North American network?

    Model answer

    It answered a query in about 200 microseconds and explored about 1,450 nodes on average, while a well-tuned Dijkstra search took about seven seconds and could explore most of the 64 million nodes.

    Explanation

    In that experiment, the hierarchy was about 35,000 times faster and reduced the search space by a factor of around 44,000.

  54. 54

    Why do route-query speed and preprocessing speed both matter for a mapping service?

    Model answer

    Fast queries support many users, while preprocessing must remain manageable so the system can incorporate road-network and traffic changes.

    Explanation

    A method with instant queries but extremely costly preprocessing or updates may not be practical at world scale.

  55. 55

    Why is reducing route-query time to less than a millisecond valuable for a widely used mapping service?

    Model answer

    Millions of users may request routes at once, so very fast searches help the service handle high demand within its available computing capacity.

    Explanation

    A search taking several seconds per request would place a much larger load on the service's servers.

  56. 56

    What general lesson about algorithm design is illustrated by Dijkstra's approach to simplicity?

    Model answer

    Avoiding unnecessary complexity can make an algorithm more reliable and easier to reason about.

    Explanation

    Dijkstra emphasized thinking carefully about a problem and avoiding avoidable complications.

  57. 57

    How has Dijkstra's algorithm influenced later shortest-path methods?

    Model answer

    Many later shortest-path algorithms continue to use Dijkstra's algorithm or components of it as a foundation.

    Explanation

    The content describes later methods, including contraction-hierarchy variants, as retaining Dijkstra-based search ideas.

  58. 58

    What principle about responsibility does Dijkstra associate with programming?

    Model answer

    The programmer, not the machine, is accountable for the work produced by a program.

    Explanation

    This principle supports the importance of careful, thoughtful, and reliable software design.

1 of 58
Question 1 of 58

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent