Algorithms and OOD (CSC 207 2014F) : Outlines

# Outline 42: Implementing Dictionaries with Arrays or Lists

Held: Monday, 17 November 2014

Summary

We consider a simple implementation of dictionaries through linked lists of key/value pairs. These are often called "association lists".

Related Pages

Overview

• Implementing dictionaries, mark I.
• Looking ahead: A better implementation.

• Continue lab partners.
• I should have MAP and Independent applications in a moment

### Upcoming Work

• Homework: Phase 1 of project (Class design, Algorithm design, I/O subsystem) due Wednesday
• No reading for Tuesday.

### Extra Credit

• CS Extras Thursday: Text Recognition in Maps
• CS Table Friday: ShellShock

#### Peer Support

• Ajuna's Radio show Mondays at 8pm. Listen to African music. TONIGHT!
• Ezra's Radio show Thursdays at midnight. Radio melodrama.
• Charlie's Friday Night "War in Animated Film" ExCo
• Copehagen on Nov. 20.

#### Miscellaneous

• VP Student Affairs Candidate Open Sessions
• Wednesday, 4:15, JRC 209
• Friday next, 4:15, JRC 209

## Implementing dictionaries, Mark 1

• The simplest approaches: Store key/value pairs in a list or array.
• Some of the same design questions as priority queues: Do we store them in order or unordered.
• For our sample version, we'll store them unordered.
• get involves searching until you find a key or run out of elements
• put involves adding it at an available spot
• We'll use linked nodes, with a dummy node at the front

## Looking ahead: Implementing dictionaries, Mark 2

• Can we do better than O(n) for get? (Or, alternately, O(n) for for put, which still requires O(logn) for get?)
• What are techniques we've used for improving algorithms in the past?
• Divide and conquer
• Randomness and luck
• Thinking outside of the box
• ...
• What's a divide-and-conquer approach?
• Looking up elements is like binary search
• Can we build an easy to extend structure that mimics binary search?
• Idea: Instead of having one link from each node, we have two: One for the smaller keys, one for the larger keys.
• We'll return to this approach in the next class.