Algorithms and OOD (CSC 207 2014S) : Outlines

# Outline 39: Implementing Dictionaries with Arrays or Lists

Held: Wednesday, 9 April 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.

• No writeup today (particularly since there's no lab today)!
• HW 6 remains due tonight.
• Exam 2 makeup due Thursday night (printed in class Friday).

### Extra Credit

• http://www.strikingly.com/pioneerweekend
• Any one Spring into Humanities (or is it vice versa) talk.
• Get and wear one of the 1 in 4 shirts next week.
• CS extra Thursday: Software to enhance wellness: The DavisJan team.
• CS table Friday: Lambda in Java 8.
• CS extra next Monday: Walker and Liberto on bluetooth.

## 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.

Copyright (c) 2013-14 Samuel A. Rebelsky.

This work is licensed under a Creative Commons Attribution 3.0 Unported License. To view a copy of this license, visit `http://creativecommons.org/licenses/by/3.0/` or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.