Algorithms and Data Structures
G52ADS Coursework for Autumn 2008
Formal Coursework
General Introduction
- This is an unofficial page. For all formal details, see Andrew J. Parkes and his Technicolor website.
- From 1st year Programming, you should know: Core Java 5+, including Collections and Generics.
- By this exercise, you should know jUnit 4.5. It is well worth learning, as it is the industry-wide standard testing tool. Birmingham School of CS has a decent tutorial on-line.
- It's heartily recommended that you learn to use Java Logging and a version control system such as Subversion or Mercurial. (There could have been a lecture or two on CVS in G51SWT.)
- It's heartily recommended that you learn to use and one of great IDEs there are for Java. The big & free IDEs are NetBeans and Eclipse, then there is JBuilder, and last but not least, there is a very nice "learn Java" IDE by the name of Blue J.
- The recommended Java textbook is the 4th edition of Eckel's Thinking in Java (available in the library or at Amazon). The first seven chapters are available for free here. The complete, if slightly out-dated, 4th revision of the 3rd edition is available for free here.
- When stuck, don't panic. Try to think for a bit. Then try Google, the documentation, and the textbook, and when all fails, go and see Jakub in B78. Beware, though: If he can google up the answer within five seconds, he may be reluctant to answer better questions you could have in the future.
The Assignment
Please read the official brief here. In essence, the goal is to implement interfaces SimpleMap and AdvancedMap as declared here. This is:
/**
* A simple Map-like interface. A subset of java.util.Map.
*/
public interface SimpleMap<V> {
/**
* Associates the specified value with the specified key in this map.
*
* @param key Key to insert
* @param v Value to associate with key
* @return If the map has an entry with k already, the associated
* value is returned. Otherwise, null.
*/
public V put(int key, V value);
/**
* Retrieves the value with associated with the specified key in this map.
*
* @param key Key we are retrieving
* @return If the map has an entry with key already, the associated
* value is returned. Otherwise, null.
*/
public V get(int key);
/**
* A destructive element query. Deletes the key-value pair, returning value.
*
* @param key Key we are retrieving
* @return If the map has an entry with key already, the associated
* value is returned. Otherwise, null.
*/
public V remove(int key);
/**
* Returns the number of elements in the SimpleMap.
* @return The number of elements in the SimpleMap.
*/
public int size();
/**
* Returns true, if there are no elements in the SimpleMap.
* @return true, if there are no elements in the SimpleMap.
*/
public boolean isEmpty();
/**
* Produces a human-readable representation of the map. Notice that to conform
* to the contract of Collection, you should print out all elements.
*
* @return A String with human-readable representation
* of the elements inside the SimpleMap.
*/
@Override
public String toString();
}
/**
* An advanced Map-like interface for implementations based on semi-balanced trees.
* A superset of SimpleMap. Akin to java.util.Map.
*/
public interface AdvancedMap<V> extends SimpleMap<V> {
/**
* Sets the maximum imbalance of the tree.
*
* @param k Upper bound on the imbalance. Read -1 as no limit on imbalance.
*/
public void setMaxImbalance(int k);
/**
* Automatically sets the maximum imbalance of the tree to suit the input.
* Calls setMaxImbalance internally.
*/
public void setAutoImbalance();
/**
* Produces a human-readable representation of the map in Newick Format:
* http://en.wikipedia.org/wiki/Newick_format
* with leaf nodes named, and nothing but leaf nodes names. Use keys to
* label nodes. Notice that this largely conforms to the contract of
* Collection, saying you should print out all elements.
*
* @return A String with human-readable representation
* of the elements inside the AdvancedMap in Newick Format.
*/
// @Override
public String toString();
}
This should be done first using linked lists (SimpleMapImpl1), and then properly, using (semi)balanced search trees (SimpleMapImpl2, AdvancedMapImpl).
Submission
You are given two interfaces (SimpleMap, AdvancedMap),
three stubs (SimpleMapImpl1, SimpleMapImpl2, AvancedMapImpl),
and a stub of a test suite (SimpleTests) in
a zip file, and you are expected to submit a zip file
with an implementation extending the stubs, which passes the suitably extended test suite SimpleTests,
including all source code,
via cw.
Please work on your own.
See more of Jakub's
homepage or the list of
exercises, if you please.