CS 223 In-Labs
In-Lab 1--Create a simple hash table
Due: at the end of lab, Thursday September 9, 2004
Objective:
To understand the components of a hash table, including:
- The array to hold the data
- The hash function to map the key to the array index
- Collision resolution
Create a simple hash table
- You can use either an array or an ArrayList for the hash table
- You should create a class to hold the data, which will be a key, value pair
- You can use anything you want for your key and value
- For this in-lab assignment, best to keep it simple
- Use a simple hash function
- If your key is an integer, just mod by the table size
- If your key is a String, use the simple hash function given in lecture, or in your book.
- For collision resolution, use open addressing with Linear Probing
- This is covered on pages 411-421 in your text
Your program should include:
- A class to hold the key-value pairs
- A class to hold the array of key-value pairs
- A method to add data to the table
- Since the hash function and collision resolution method are so simple, you
could include them in this method, or you could write separate methods for them.
- You can hard code input, read it from a file, or input it from the keyboard, however you prefer.
- A way to print out the contents of the hash table for testing.
- You may test your program with a separate class for the driver, or just put a main method
in the same class as the array of key-value pairs.
- If you have time, you should implement a search method: Given a key, return the value
associated with that key.
In-Lab 2--Experiment with a HashMap
Due: at the end of lab, Thursday September 16, 2004
Objective:
To practice using the HashMap class from the Java Collection Framework
The HashMap class
Go to the Java
API and look at the methods in the HashMap class. Be sure to read about
the constructors, as well as the other methods.
What to do
- You are to try out the methods in the HashMap class so you are
sure you know how to call them, and what they do when called.
- To do this, you can start with a little code declaring an object of type HashMap
- It will put some data in the hash table.
- It will then call some of the methods in the HashMap class.
- Download the code, compile it, and run it, so you can see what it
does.
- Modify the code so you become familiar with how the Collection Framework works,
how the methods in the HashMap class work, and what they do.
- To do this, write some code that calls most of the other methods,
and and write enough code so you output the results of the calls.
Ideas of other things to try
- Change the method of inputting data. When you use this class, you
will almost certainly be inputting from a class with key-value pairs.
In this case, you would call put with the arguments getKey and getValue
which would be methods in the key-value class.
- You might try making it input the thesaurus that you are using in your Out Lab.
- Change the constructor so you control the initial size of the hash table
and/or the maximum load factor. Then get it to rehash the table.
See if you notice a time delay while rehashing is going on.
In-Lab 4--Rotations with AVL trees
Due: at the end of lab, October 7, 2004
In-Lab 5--Building Red-Black Trees
Due: at the end of lab, October 14, 2004
Objective: Practice building Red-Black trees
Applet to use to check your work.
Build these Red-Black trees
- 8, 5, 12, 3, 2, 1
- 1, 2, 3, 4, 5, 6, 7, 8
- 30, 20, 40, 35, 37
- 82, 75, 98, 60, 79, 80, 65, 62
- 48, 76, 27, 52, 87, 50, 51, 92, 49, 90
- 4, 2, 6, 5, 7, 16, 15, 14, 13, 12, 8, 10
Hand in:
Hand in your diagrams of trees, showing the rotations, reasonably neat.
It is expected that every diagram will be correct, since you can check it
with the applets.
In-Lab 6--Work on Red-Black Trees
- This in-lab will be devoted to working on the code for your red-black tree
- Mike will show you how deletions are done in a red-black
tree and give you some pseudocode.
Grading Criteria for Red-Black Tree Program
In-Lab 7--Dynamic Programming
Due: at the end of lab, October 28, 2004
Objective: Become familiar with dynamic programming
What to do:
For this lab, you should do #3 and #4 of the exercises on page 133 of the
Neapolitan/Naimipour text. Because you may not all have your text in lab,
I will spell out the assignment below.
- Implement the two algorithms for finding the binomial coefficient given in
your text(algorithms 3.1 and 3.2), or in class.
One uses recursion to
find the binomial coefficient, the other uses dynamic programming.
- Study the preformance of the two algorithms using different
problem instances (i.e. different n and k values)
- You should devise ways to "study" the preformance. One way
might be to count comparisons, but you may be able to come up with
better ways. Large values of n and k will show greater differences than
small values.
- Write a report stating how you "studied" the performance and
what your study showed. This is to turn in.
- Modify the algorithm that uses dynamic programming so that it is more efficient.
- You will turn in this source code, and a run. Be sure you
include comments with the source code stating how you modified
the algorithm. This will be considered the second part of your report.
In-Lab 8--Chained matrix multiplication
Due: at the end of lab, November 4, 2004
In-Lab 9--Test your checkboard
Due: at the end of lab, November 18, 2004
In-Lab 10 -- There will be lab today Dec 2
There are two things to do in lab today
- Demo your program that inputs a graph, then finds the shortest path
between a given node, and all the other nodes in the graph.
- Fill out evaluations for this course.
In-Lab 11 -- Fill our a course evaluation
Dec 9
Your lab this week is to fill out a course evaluation
Your have two choices for this:
- Go to lab at your usual time, and fill out the course evaluation there
- Mike will keep track of who comes to lab to do the evaluation
- Fill it out on your own time, and email me that you have done so
- On the subject line of the email, just put "Survey done"
- Be sure I can tell who the email is from
To fill out the evaluation go to:
http://www.cs.montana.edu/survey/
If you are in any other CS course, you should also fill out a course evaluation for that course