liveBook · Manning

Shortest path

As explained in Learn Haskell by Example

A shortest path is a path between two graph nodes having minimal total length or cost.

A shortest path connects two graph nodes with the fewest total steps or lowest cost. In a word ladder, each word is a node and each valid one-step transformation is an edge; every edge has equal cost. section 5.1.1

A word-ladder program can approach the task incrementally:

  • Read the starting and ending words. section 5.1.1
  • Build a graph from a dictionary, connecting words reachable in one valid step. section 5.1.1
  • Search the graph for the shortest path between the two words. section 5.1.1

Cat to dog

The chain cat → hat → heat → heal → held → dole → does → dogs → dog is valid but longer than cat → cats → tags → goat → got → dog, making the second chain a shortest solution among the examples. section 5.1.1

Figure 5.2 A ladder graph for a selection of English words
figure

Use the ladder-graph figure to inspect how words become nodes and valid transformations become connecting edges. section 5.1.1

How Learn Haskell by Example covers it

How deep it goes
Defines nodes, edges, paths, directions, and costs, then stops before specifying a search algorithm.
Examples
Compares two cat-to-dog word chains and visualizes a selection of ladder words as a graph.
What it assumes
Teaches graph vocabulary and edge direction from the beginning while assuming familiarity with valid word transformations.
What you can do after
Builds a word-ladder graph and identifies a shortest chain between two words.
How it connects
Connects shortest paths with graphs, nodes, edges, paths, word ladders, dictionaries, and polymorphic Haskell types.

Also explained in

Compare how 6 books explain shortest path →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Haskell by Example. The section links point to the parts of the book it draws on.