Search code examples
sqldatabasedata-structuresabstract-data-type

When to choose a Dictionary ADT


In college we learned the three main abstract data types were Containers (Stacks, Queues, and Tables), Dictionaries, and Priority Queues. There are probably an unlimited number of ways to group ADTs at a high level like this, but this is a good start.

I don't really understand when you would choose a Dictionary ADT to solve a computational problem though. Stacks and Queues seem to come up naturally, but not dictionaries.

The one example I can think of is a dictionary in the sense we use it in the real world. A dictionary keeps and ordered set of words for fast lookup, and what you get when you look up a word is: correct spelling, how to pronounce the word, what part of speech it is, definition of the word, etc.

As I'm starting to understand it better, the more it seems like a "dictionary" is another way to think of querying a database. When you write a SQL SELECT statement, you're usually looking for a when a primary key equals a certain value (not always of course, you can select on any field that exists in a table).

Is this the correct way to think of a Dictionary ADT? Or is the intended use more limited than this...


Solution

  • Your SQL example is pretty accurate. You're searching for a primary key (the key of the dictionary entry) to get some fields (the values) associated with it.

    I personally found dictionaries useful in my game programming courses. I would load my resources and then cache them into a dictionary for later use. This way, I didn't have to know an index number for a specific resource, I could give it a key that would relate to the resource.