Monash University > CSSE > CSE1303 > Part A> Pracs > Prac A6
This prac covers material from lectures A14 to A15 and Tutorial A6.
To write a simple spell checker.
In this prac will use a Hash Table to implement a simple spell checker. The idea behind the program is to read a dictionary into a Hash Table, then check every word in a nominated file to see whether it is in the Hash Table. Any word not found will be assumed to be misspelt and will be printed.
The marks for Preparation will be awarded only if the preparation is complete before the start of the class.
unsigned hash(char* s)
{
int i = 0;
unsigned value = 0;
while (s[i] != '\0')
{
value = (value + 13 * s[i]) % 11;
i++;
}
return value;
}
calculate the hash values of the following names:
Note: You must use dynamic memory for your strings. This means your Hash Table will be an array of char* (ie. char* table[11];
This also means that for the advanced question you will need to change your Hash Table to be char** table; for dynamic of re-sizing.
Also make sure you initialise all of these strings to NULL before you use the Hash Table.
Write C program which uses a Hash Table of size, 24593, the following hash function:
#define TABLESIZE 24593
#define PRIME 12289
unsigned hash(char* s)
{
int i = 0;
unsigned value = 0;
while (s[i] != '\0')
{
value = (value + PRIME*s[i]) % TABLESIZE;
i++;
}
return value;
}
and has a menu with the following options:
Important: You must use the linear probing implementation.
You must also free any memory allocated dynamically.
Change the program you wrote in Question 1, so that instead of a menu the program does the following steps:
In the above implementation of a Hash Table the size of the table was fixed. In this part of the prac we extend the implementation so that the size of the table is dynamic.
Note: When you change the size of the Hash Table you will need to insert all the items from the old Hash Table into the new Hash Table.
Note: Make sure you deallocate any memory you no longer require.
Last modified: Thursday 26 June 2003 14:45:30