Fundamentals of Computer Science II (CSC-152 2000S)


Class 42: Binary Search Trees

Back to Dictionaries. On to Hash Tables.

Held Tuesday, April 18, 2000

Overview

Today we consider two simple implementations of dictionaries: association lists and binary search trees.

Notes

Contents

Summary


A Dictionary Interface


/**
 * Very simple dictionaries that map keys to values.
 *
 * @author Samuel A. Rebelsky
 * @version 1.1 of November 1999
 */
public interface Dictionary {
  /**
   * Add an entry to the dictionary.
   * Pre: The key and value are non-null.
   * Pre: The key can be compared to other values in the dictionary.
   * Post: Subsequent calls to get(key) will return value.
   *
   * @exception Exception
   *   If the key cannot be compared.
   */
  public void add(Object key, Object value)
    throws Exception;

  /**
   * Determine if a particular key is in the dictionary.
   * Pre: None.
   * Post: Returns true if the key is in the dictionary;
   *       Returns false otherwise.
   */
  public boolean contains(Object key);

  /**
   * Look up an entry in the dictionary.
   * Pre: The key is non-null.
   * Pre: The key can be compared to other values in the dictionary.
   * Post: Returns the value most recently "put" with the key.  
   *
   * @exception Exception
   *   If the key cannot be compared or there is no such entry.
   */
  public Object lookup(Object key)
    throws Exception;

  /**
   * Get a list of all the keys in the dictionary.
   * Pre: (None)
   * Post: Returns a list of all the keys.
   */
  public SimpleList getKeys();
} // interface Dictionary


A Simple Dictionary Implementation

Search Trees

Another Perspective: Binary Search Trees for Binary Search


History

Tuesday, 18 January 2000

Tuesday, 18 April 2000

Back to Dictionaries. On to Hash Tables.


Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.

This page may be found at http://www.math.grin.edu/~rebelsky/Courses/CS152/2000S/Outlines/outline.42.html

Source text last modified Tue Apr 18 09:58:25 2000.

This page generated on Tue Apr 18 09:59:20 2000 by Siteweaver. Validate this page's HTML.

Contact our webmaster at rebelsky@grinnell.edu