Maps - Data Structures - Lecture Slides, Slides of Data Structures and Algorithms

In the subject of the Data Structures, the key concept and the main points, which are very important in the context of the data structures are listed below:Maps, Relation, Set of Keys, Values, Object, Duplicate Keys, Implemented, Java Map Interface, Hashmap, Hashtable

Typology: Slides

2012/2013

Uploaded on 04/23/2013

saratey
saratey 🇮🇳

4.3

(10)

86 documents

1 / 14

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Maps
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download Maps - Data Structures - Lecture Slides and more Slides Data Structures and Algorithms in PDF only on Docsity!

Maps

Maps

Map is a relation between set of keys and set ofvalues

Map ADT

 Java provides a Map interface  Some implementing classes  Hashmap^  Hashtable implementation of a map interface  Hashtable^  Extended dictionary class Map Hashmap Hashtable

Example of Maps

 Taurus;Kesden, Greg  RX-8;Slater, Don  Accord;Mouse, Mickey  Camry;Roberts, Jim  Dakota;Pattis, Rich  F-150;Stehlik, Mark  I-300;McElfresh, Scott  big yellow bus;Cortina, Tom

Java Dictionary Class - abstract

The Dictionary class is the abstract parent ofHashtable, which maps keys to values.

A Dictionary object, every key is associated with atmost one value

Given a Dictionary and a key, the associatedelement can be looked up

Any non-null object can be used as a key and as avalue.

Some Methods :  get ( Object key)  put ( Object key, Object value)  remove ( Object key)

Java Tools - HashMap Class

 This implements the Map interface  HashMap permits null values and null keys.  Constant time performance for get and put operations  HashMap has two parameters that affect its performance: initial capacity and load factor  Capacity – number of buckets in the Hash Table  Load factor – How full the Hash Table is allowed to get beforecapacity is automatically increased using rehash function.

More on Java HashMaps  HashMapHashMapHashMapHashMap (int initialCapacity)  putputputput

Object key, Object value)  getgetgetget

Object key) – returns Object  keySetkeySetkeySetkeySet () Returns a setsetsetset view of the keys contained in this map.  valuesvaluesvaluesvalues () Returns a collectioncollectioncollectioncollection view of the values contained in this map.

Sets

Classes that implements set interface^ 

public class HashSet  Implements Set interface using HashTable  Offers constant time performance  public class TreeSet  Implements Set interface using TreeMap  Sorted set will be ascending order according to thenatural order

Exercise

 Write a method  public static Set intersect(Set A, Set B)  That takes two sets A and B and return theintersection of the two sets  Write a method  public static Set union(Set A, Set B)  That takes two sets A and B and return the union ofthe two sets