Interfaces finalized Hashing Ch. 6 CLR (see class resources page)

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming Lecture 5 The Collections API.
Advertisements

Sequence of characters Generalized form Expresses Pattern of strings in a Generalized notation.
Queues and Stacks.  Can receive multiple requests from multiple sources ◦ How do we services these requests?  First come, first serve processing 
Chapter 6 Linked Structures © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
CS 171: Introduction to Computer Science II Hashing and Priority Queues.
Maps. Hash Tables. Dictionaries. 2 CPSC 3200 University of Tennessee at Chattanooga – Summer 2013 © 2010 Goodrich, Tamassia.
The Java Network API and Parsing HTML java.net.* javax.swing.text.html.*
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 17: Topological Sort Algorithm.
1 L43 Collections (3). 2 OBJECTIVES  To use the collections framework interfaces to program with collections polymorphically.  To use iterators to “walk.
Hash Tables1 Part E Hash Tables  
24-Jun-15 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
© The McGraw-Hill Companies, 2006 Chapter 17 The Java Collections Framework.
Hash Tables1 Part E Hash Tables  
Grokking Hash Tables. A hash table is… Just a data structure that’s used to establish a mapping between arbitrary objects Not to be confused with Map.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 20 Lists, Stacks, Queues, and Priority.
CSE 143 Lecture 7 Sets and Maps reading: ; 13.2 slides created by Marty Stepp
Java Collections. Collections, Iterators, Algorithms CollectionsIteratorsAlgorithms.
CS Collection and Input/Output Classes CS 3331 Fall 2009.
CS-2851 Dr. Mark L. Hornick 1 Tree Maps and Tree Sets The JCF Binary Tree classes.
COMP T2 Lecture 5 School of Engineering and Computer Science, Victoria University of Wellington Thomas Kuehne Maps, Stacks  Thomas Kuehne, Marcus.
CS2110: SW Development Methods Textbook readings: MSD, Chapter 8 (Sect. 8.1 and 8.2) But we won’t implement our own, so study the section on Java’s Map.
A Level Computer Science Topic 9: Data Structures T eaching L ondon C omputing William Marsh School of Electronic Engineering and Computer Science Queen.
CSC 213 – Large Scale Programming. Today’s Goal  Consider what will be important when searching  Why search in first place? What is its purpose?  What.
Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
(c) University of Washington14-1 CSC 143 Java Collections.
Lecture 10: Class Review Dr John Levine Algorithms and Complexity March 13th 2006.
Copyright © 2002, Systems and Computer Engineering, Carleton University Hashtable.ppt * Object-Oriented Software Development Unit 8.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington2012 More Collections: Queues,
Hash Tables1   © 2010 Goodrich, Tamassia.
Building Java Programs Chapter 11 Lecture 11-1: Sets and Maps reading:
Data structures Abstract data types Java classes for Data structures and ADTs.
Sets, Maps and Hash Tables. RHS – SOC 2 Sets We have learned that different data struc- tures have different advantages – and drawbacks Choosing the proper.
LECTURE 34: MAPS & HASH CSC 212 – Data Structures.
CSC 212 – Data Structures Lecture 37: Course Review.
CSE 143 Lecture 14 (B) Maps and Grammars reading: 11.3 slides created by Marty Stepp
13-1 Sets, Bags, and Tables Exam 1 due Friday, March 16 Wellesley College CS230 Lecture 13 Thursday, March 15 Handout #23.
3-February-2003cse Collections © 2003 University of Washington1 Java Collections CSE 403, Winter 2003 Software Engineering
Games Development 2 Overview & Entity IDs and Communication CO3301 Week 1.
Author: Takdir, S.ST. © Sekolah Tinggi Ilmu Statistik.
CSS446 Spring 2014 Nan Wang.  To understand the implementation of linked lists and array lists  To analyze the efficiency of fundamental operations.
Building Java Programs Bonus Slides Hashing. 2 Recall: ADTs (11.1) abstract data type (ADT): A specification of a collection of data and the operations.
Collections Data structures in Java. OBJECTIVE “ WHEN TO USE WHICH DATA STRUCTURE ” D e b u g.
Copyright 2010 by Pearson Education Building Java Programs Chapter 10, 11 Lecture 22: 143 Preview optional reading: 10.1,
Collections Mrs. C. Furman April 21, Collection Classes ArrayList and LinkedList implements List HashSet implements Set TreeSet implements SortedSet.
Set and Map IS 313, Skeletons  Useful coding patterns  Should understand how and why they work how to use  possible quiz material.
More Java: Static and Final, Abstract Class and Interface, Exceptions, Collections Framework 1 CS300.
STL: Maps Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University.
Week 15 – Wednesday.  What did we talk about last time?  Review up to Exam 1.
Week 9 - Monday.  What did we talk about last time?  Practiced with red-black trees  AVL trees  Balanced add.
Maps Nick Mouriski.
1 Maps, Stacks and Queues Maps Reading:  2 nd Ed: 20.4, 21.2, 21.7  3 rd Ed: 15.4, 16.2, 16.7 Additional references: Online Java Tutorial at
“The desire for safety stands against every great and noble enterprise.” – Tacitus Thought for the Day.
Sets and Maps Chapter 9. Chapter Objectives  To understand the Java Map and Set interfaces and how to use them  To learn about hash coding and its use.
CSE 143 Lecture 11: Sets and Maps reading:
Lecture 18 March 29, 2011 Formal Methods 3 CS 315 Spring Adapted from slides provided by Jason Hallstrom and Murali Sitaraman (Clemson)
COMP 103 Maps and Queues. RECAP  Iterators (for-each loop)  Bag, Sets, and Stacks - a class, not interface TODAY  Maps and Queues 2 RECAP-TODAY QUICK.
Building Java Programs Generics, hashing reading: 18.1.
Week 15 – Monday.  What did we talk about last time?  Tries.
Lecture14: Hashing Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)
Data Structures Interview Questions.
Week 15 – Monday CS221.
JCF Hashmap & Hashset Winter 2005 CS-2851 Dr. Mark L. Hornick.
CS240: Advanced Programming Concepts
Road Map CS Concepts Data Structures Java Language Java Collections
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.2 : Hash Tables Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich, Tamassia and.
CS210- Lecture 16 July 11, 2005 Agenda Maps and Dictionaries Map ADT
CS 240 – Advanced Programming Concepts
Set and Map IS 313,
CS2005 Week 8 Lectures Maps & Binary Trees.
Presentation transcript:

Interfaces finalized Hashing Ch. 6 CLR (see class resources page)

Administrivia P1 Update 1 (P1 v. 1.1) released today On the web site; no paper version Prof. Lane out of town, Jan 27-Jan 30 May have partial access Jason will also track cs351 mail list

Progress meter Milestone 1 due: Jan 31, 3:00 PM (next Mon) 5 days left At this point, you should have implemented: Test program At least put(), get(), containsKey(), remove(), size(), isEmpty() By end of Friday: Complete MondoHashMap By Mon afternoon: Testing and documentation

Thoughts on Hashing

A hash table is... Just a data structure that’s used to establish a mapping (in the mathematical sense) between arbitrary objects Every key is assigned (mapped to) a single value Each key appears only once A value may appear more than once Not to be confused with java.util.Map An interface that specifies methods that a program could call to get/set/query key/value mappings Hash table is one (but not only) way to make a Map

Examples of mappings 37 → (sqrt(37)) → studentRecord(“J. Student”) “ACM” → “ “Lane” → { “ “ }

If all keys were integers... If all keys were (small, nonnegative) integers Mapping could be made w/ a simple table Object[] mapTab=new Object[1000]; mapTab[key]=value; But how do you use an arbitrary object ( String, Date, StudentRecord, etc.) as a key? Could use the bitwise representation of key object as an integer index Ick! Could assign each key object a unique index value Doable, but painful

Desiderata An object that gives quick lookup for arbitrary key objects Doesn’t require vast space Doesn’t need to know anything about the key or value object types (e.g., what’s a good hash code for them)

Hash tables and codes Answer: introduce an intermediate step Hash function: turns an arbitrary key into a hash code (integer) Use hash code to look up key/val pair in table table[h(key)]= Or, in Java: table[key.hashCode()]=new Entry(key,value);

The “big picture” MondoHashMap “ACM” [0] [N] get(“ACM”) h(”ACM”) compress(h(ACM”)) “ACM” “ Map.Entry “ cs.unm.edu”

Easy enough, in theory... Practical gotchas How does the compress() function work? Resizing the hash table Handling collisions What if !k1.equals(k2), but compress(k1.hashCode())==compress(k2.hashCode) ? Handling remove() keySet(), values(), and entrySet()

Design exercise Given: A LinkedList class, with methods size(), prepend(), append(), first(), last(), iterator(), removeFirst(), and removeLast() Design: A sub-class, StackGenList, that supports a method getStackView() which returns a Stack object that, in turn, supports push(), pop(), topElement(), and depth() Constraints: You do not have access to the internals of the LinkedList (it has no protected members) You may not copy any of the LinkedList data The Stack view and the LinkedList must always remain synchronized