Assignment 2: Ordered Word Ladders

An ordered word ladder ('owl') is an alphabetically-ordered sequence of words where each word in the sequence differs from its predecessor by one action:

  1. changing one letter, e.g. barn→born

  2. adding or removing one letter, e.g. band→brand and bran→ran

The following are examples of word ladders of different length:

Phase 1

At the heart of the assignment is a function that compares 2 arbitrary null-terminated strings and returns true if the strings satisfy one of the 2 conditions above, and false otherwise. This function has signature:

   1 bool differByOne(char *, char *)

Write such a function and of course test it.

Phase 2

Generate a graph that represents all the words in the input that differ by one. Each word is represented by a vertex in the graph, and vertices are adjacent if the corresponding words differ by one. For example, if a dictionary consists of the 7 words an ban bean ben hen mean men then the graph that represents all ordered word ladders would be drawn as:

             0
             |
             1 
           /   \
          2 --- 3
          |    / \
          5---6---4

where the vertices 0..6 represent the 7 words in the given order. There are lots of ordered word ladders in this graph: for example, 0→1→2→5 representing an→ban→bean→mean. Any path between any two vertices in the graph is an owl, but notice that, although the edges are undirected, you can select vertices only in ascending order (hence the term 'ordered' in 'owl').

In this phase of the assignment you are asked to create a graph for a dictionary, and simply print the graph.

Phase 3

In this phase you must find the length of the longest owl in the graph, corresponding to the longest path.

To test your program, you should use small dictionaries until you have it working. Here are larger examples of input and output for reference:

  1. 'case' example, 4 longest ladders

  2. 'bear' example, 1 longest ladder

  3. 'aaaa' example, 24 longest ladders