Differences between revisions 53 and 54
Revision 53 as of 2019-07-19 18:48:17
Size: 2726
Comment:
Revision 54 as of 2019-07-19 18:50:39
Size: 2749
Comment:
Deletions are marked like this. Additions are marked like this.
Line 24: Line 24:
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''. The words can be found on ''stdin'', and are in dictionary order, and will have white space between them (which means they may occupy any number of lines). You may assume that they consist of just lower-case letters (''a-z'') in this assignment (so no punctuation, hyphens, capital letters ...). As you will be building graphs, you must use the graph ADT provided in lectures (use the ''Adjacency Matrix'' version). 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''. The words can be found on ''stdin'', and are in dictionary order, and will have white space between them (which means they may be all on one line, or spread out over many lines). You may assume that they consist of just lower-case letters (''a-z'') in this assignment (so no punctuation, hyphens, capital letters ...). As you will be building graphs, you must use the graph ADT provided in lectures (use the ''Adjacency Matrix'' version).

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:

  • ban→bar→boar→boat→goat, length 5

  • an→can→cane→dane→date→mate→mite→site→size, length 9

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. The words can be found on stdin, and are in dictionary order, and will have white space between them (which means they may be all on one line, or spread out over many lines). You may assume that they consist of just lower-case letters (a-z) in this assignment (so no punctuation, hyphens, capital letters ...). As you will be building graphs, you must use the graph ADT provided in lectures (use the Adjacency Matrix version).

For example, if a dictionary consists of the 12 words case cast cat cats cave cost cove love post sale save suave then the graph that represents all ordered word ladders is:

             0
           /   \
          1     4
         / \   / \
        2   5 6  10
        |   | |   |
        3   8 7  11

where the vertices 0..11 represent the 12 words in the given order. You can check yourself that each path in the graph corresponds to an 'owl'. This owl graph is interesting because it has 4 maximal word ladders, which are easy enough to read off the graph of course.

Owl graphs typically are not trees, and typically have a single maximal owl. One reason for this is that (English) dictionaries often contain subsets of 3 or 4 letter words that are closely related. Take the dictionary pan pen pin which generates the complete graph on 3 vertices:

           0
          / \
         1---2

This clearly has one maximal path of length 3. More basically, consider a single-letter dictionary a b c d, which generates a tetrahedron and has maximal owl length 4.

Assignment2 (last edited 2019-07-31 22:35:13 by AlbertNymeyer)