Algorithms and OOD (CSC 207 2014F) : EBoards

CSC207.01 2014F, Class 41: Implementing Dictionaries


Overview

Preliminaries

Admin

Upcoming Work

Extra Credit

Academic

Peer Support

Miscellaneous

Questions

Review: Thinking about data structures

You have to implement dictionaries in the next two hours. You don't get to use the java.util.* stuff. What do you do?

Associative arrays

Association lists

Techniques for improving the implementation

Can we do better than O(n) for all of the operations? Suppose we want get to be less than O(n), but we're okay with add and remove being O(n)?

Strategy:

Strategy:

Binary search trees (BST)

Break up the data into parts

    public class Node<K,V>
    {
      K key;
      V value;
      Node<K,V> smaller;    // Things with smaller keys
      Node<K,V> larger;     // Things with larger keys
    }

If we can arrange the tree in advance, we have O(logn) get

How do we keep them balanced? Take 301