Now with a speaking professor! (hopefully...)

Slides:



Advertisements
Similar presentations
The Dictionary ADT Definition A dictionary is an ordered or unordered list of key-element pairs, where keys are used to locate elements in the list. Example:
Advertisements

Hashing as a Dictionary Implementation
Sorting Algorithms. Motivation Example: Phone Book Searching Example: Phone Book Searching If the phone book was in random order, we would probably never.
CSE 143 Lecture 7 Sets and Maps reading: ; 13.2 slides created by Marty Stepp
1 Hash Tables  a hash table is an array of size Tsize  has index positions 0.. Tsize-1  two types of hash tables  open hash table  array element type.
CS212: DATA STRUCTURES Lecture 10:Hashing 1. Outline 2  Map Abstract Data type  Map Abstract Data type methods  What is hash  Hash tables  Bucket.
LECTURE 37: ORDERED DICTIONARY CSC 212 – Data Structures.
Week 6 - Friday.  What did we talk about last time?  Recursive running time  Fast exponentiation  Merge sort  Introduced the Master theorem.
Chapter 11 Heap. Overview ● The heap is a special type of binary tree. ● It may be used either as a priority queue or as a tool for sorting.
Building Java Programs Chapter 11 Lecture 11-1: Sets and Maps reading:
LECTURE 36: DICTIONARY CSC 212 – Data Structures.
LECTURE 34: MAPS & HASH CSC 212 – Data Structures.
Chapter 12 Hash Table. ● So far, the best worst-case time for searching is O(log n). ● Hash tables  average search time of O(1).  worst case search.
APS105 Lists. Structures Arrays allow a collection of elements –All of the same type How to collect elements of different types? –Structures; in C: struct.
CHAPTER 9 HASH TABLES, MAPS, AND SKIP LISTS ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++,
Week 15 – Wednesday.  What did we talk about last time?  Review up to Exam 1.
Hash Tables ADT Data Dictionary, with two operations – Insert an item, – Search for (and retrieve) an item How should we implement a data dictionary? –
Maps Nick Mouriski.
CSE 143 Lecture 11: Sets and Maps reading:
CSC 143T 1 CSC 143 Highlights of Tables and Hashing [Chapter 11 p (Tables)] [Chapter 12 p (Hashing)]
CSC 212 – Data Structures Lecture 28: More Hash and Dictionaries.
CMSC201 Computer Science I for Majors Lecture 23 – Algorithms and Analysis Prof. Katherine Gibson Based on slides from previous iterations.
An Array-Based Implementation of the ADT List
CSE373: Data Structures & Algorithms Priority Queues
11 Map ADTs Map concepts. Map applications.
Design & Analysis of Algorithm Hashing
Sorted Dynamic Array Bag and Set
CSE373: Data Structures & Algorithms
Chapter 11 Heap.
Week 7 - Friday CS221.
Hashing & HashMaps CS-2851 Dr. Mark L. Hornick.
CSE373: Data Structures & Algorithms Lecture 6: Hash Tables
CMSC201 Computer Science I for Majors Lecture 21 – Dictionaries
CMSC201 Computer Science I for Majors Lecture 22 – Searching
Slides by Steve Armstrong LeTourneau University Longview, TX
Week 8 - Wednesday CS221.
Instructor: Lilian de Greef Quarter: Summer 2017
October 30th – Priority QUeues
Binary Search Tree Chapter 10.
Hashing Exercises.
Cse 373 April 12th – TreEs.
© 2013 Goodrich, Tamassia, Goldwasser
Dictionaries 9/14/ :35 AM Hash Tables   4
Hash Tables 3/25/15 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M.
Lecture 3: Working with Data Structures
The Dictionary ADT Definition A dictionary is an ordered or unordered list of key-element pairs, where keys are used to locate elements in the list. Example:
Road Map CS Concepts Data Structures Java Language Java Collections
Advanced Associative Structures
Hash Table.
Dictionaries < > = Dictionaries Dictionaries
Searching.
CSE 373: Data Structures and Algorithms
Chapter 21 Hashing: Implementing Dictionaries and Sets
EE 422C Sets.
Hash Tables and Associative Containers
Recitation Outline C++ STL associative containers Examples
Introduction to Dictionaries
Searching CLRS, Sections 9.1 – 9.3.
CH 9.2 : Hash Tables Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich, Tamassia and.
CH 9 : Maps And Dictionary
Sorting And Searching CSE116A,B 4/7/2019 B.Ramamurthy.
slides created by Marty Stepp
Amortized Analysis and Heaps Intro
CS210- Lecture 16 July 11, 2005 Agenda Maps and Dictionaries Map ADT
CS210- Lecture 15 July 7, 2005 Agenda Median Heaps Adaptable PQ
Chapter 12 Heap ADT © 2011 Pearson Addison-Wesley. All rights reserved.
Dictionaries < > = Dictionaries Dictionaries
CSE 326: Data Structures Lecture #14
Week 6 - Monday CS221.
Dictionary.
Presentation transcript:

Now with a speaking professor! (hopefully...) Dictionaries Now with a speaking professor! (hopefully...)

Assignment 2 Your next homework assignment is due a week from today You will need to implement a dictionary class and write a program that allows for stocks to be tracked (looking up stocks by name, updating stocks, etc.) We'll talk more about this in a bit... You can work alone or in groups of two There are two parts to the assignment that can be done separately

Dictionaries Today, we’ll be talking about a very prevalent abstract data structure: dictionaries A dictionary is a data structure that allows for multiple pieces of data (or values) to be stored, with each piece of data being associated with a key that allows us to look it up Dictionaries are also known as: Maps, associative containers, key-value stores, hashes*, etc.

Examples of dictionaries in the real world Remember phone books? Given a name, allows you to look up a phone number Given a string, look up another string Remember physical dictionaries? Given a word, look up a definition Remember thesauruses? Given a word, look up a number of words Given a string, look up a list of strings

Other examples of dictionaries? What other examples can you think of where a dictionary would be useful or appropriate?

Implementing a dictionary In class, we’ll see many examples of how dictionaries can be implemented Different implementation methods have different performance characteristics In class today, we’ll see a dictionary implementation that follows the Schroeder mantra For your next homework assignment, you’ll be implementing a more intelligent implementation technique.

Dictionary ADT All of our implementations of the Dictionary ADT will have the same functions with the same semantics How can we make sure that different classes all allow the same set of functions?

Dictionary abstract base class We will use the same Dictionary class for all of our dictionary implementations Let’s take a look at this class…

Dictionary implementation: SimpleDictionary To keep track of keys and values, we can have an array of keys and an array of values To have a key associated with a value, we can have the element at index i in the keys array correspond to the element at index i in the values array

Example SimpleDictionary<string, int> d(10); d.add("car", 12); d.add("zoo", 90); d.add("ant", 8); d.getValue("zoo"); d.remove("car"); d.add("cat", 7);

SimpleDictionary Let's take a look at how SimpleDictionary is implemented...

SimpleDictionary performance Let's take a look at the Big-O performance for some of these functions...

SortedDictionary: a better Dictionary Almost all of our functions are O(n) If we're clever, we can improve some functions to O(log n) while keeping some still at O(n) Key insight: if keys are stored in a sorted order, it's really fast to look up a key's index How?

Binary search Give me an integer between 1 and 100

Binary search 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 20 28 32 46 51 54 62 65 75 78 79 98

SortedDictionary We need to make sure our keys are stored in an appropriate order Our keys must always be sorted When we add a key/value pair, we need to: Find the right index to insert the new key at Shift every key and value over to make room for the new key/value pair Add the new key/value pair at the newly-empty index When we remove a key/value pair, we need to: Shift elements over to overwrite the element to be deleted

SortedDictionary, cont'd Whenever we need to find an index, we should use binary search to find the appropriate index int findIndex(K key, int low, int high) Return the index of the index in the range low to high of the first item in the keys array greater than or equal to 'key' I strongly strongly suggest making this a recursive function to make life easier

Finishing up Let's look at main.cpp and what the stock tracker should act like