Homework 8

22C:21 Computer Science II: Data Structures
Due Monday, April 28, 2008

1. (25 points) Implement a program that plays the "Ladders" word game. Recall that, given a "start" word and "end" word, the Ladders game involves finding a sequence of intermediate words that transforms the start word to end word, with the condition that each word in the sequence differs in exactly one letter from the prior and subsequent words.

Thus, for "adore" and "scorn," a ladder is "adore adorn acorn scorn"

And, for "white" to "black," a ladder is "whine shine swine swing sling cling clink blink blank black"

For "arise" to "sleep" the shortest ladder has 14 intermediate words! Can you find them?


Important note Our textbook supplies some detailed code for this problem. You are not allowed to directly use that code. In particular, do not use Java Maps and HashMaps in your program. Although those are good things, and you should use them where appropriate in the future, you can't use them in this program. Instead, I want you to get practice (one more time) with implementing basic data structures yourself. Requirements:
  1. Your program should take three arguments:
  2. You program should determine a minimum-length ladder for the given words, and give appropriate output.
  3. Your program should use an adjacency list representation for the graph used to represent the relationships between words. There is no need to use hashing. As you read in each word from the dictionary, simply assign it the subsequent vertex number. Your processing of the graph can then proceed almost exclusively in terms of integer-keyed vertices. (See data structure details below.)

A test file with a couple thousand test words is here.

Data structure details. For the adjacency list representation, one simple approach is to use an array, say 'wordGraph' (of size equal to number of words/vertices), of adjListHead objects. Each adjListHead object has two fields, a string to hold the relevant word, and a reference to a listNode object. Thus, for any vertex i, wordGraph[i].word can hold the word represented by vertex i, and wordGraph[i].next references a linked list of listNode items. Each listNode item has a vertexID field and a next field. If an edge (i,j) exists in the graph, then a listNode with vertexID j, must be put in wordGraph[i]'s linked list.

Submit your program (with sample output and, of course, the required README file) via ICON.