Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE 214 – Computer Science II Maps

Similar presentations


Presentation on theme: "CSE 214 – Computer Science II Maps"— Presentation transcript:

1 CSE 214 – Computer Science II Maps
Source:

2 Maps An abstract data structure for storing (key, value) data pairs
called (name, value) on Web maps may also be called dictionaries, associative arrays, etc. What’s a key? a unique identifier for accessing a piece of data like an ID What’s a value? the data

3 You have already built a type of map
PresidentsBST is a Map Each president has a unique ID president number ID provides a natural sorting/ordering Only difference: we didn’t call it a map we didn’t adhere to a specific map interface

4 Game Programmers Love Maps
Why? To store commonly used assets Example: 3D Model of a dragon suppose we need to render 3 or more identical dragons same geometry, same textures, same animations, etc.

5 What do we do? Construct Dragon object for each one Instead:
will keep track of location, animation state, damage, etc. don’t load dragon artwork 3 times Instead: load dragon artwork once store it in a dictionary (map) Optimized for fast access (log N) give map key of dragon to all Dragon objects At render time: retrieve 3D dragon model from dictionary using ID render the 3 models

6 The java.util.Map interface
Map methods: V get(K key, V value) V put(K key, V value) V remove(Object key) Colletions<V> values() – to help with getting an Iterator Manages Map.Entry objects

7 The java.util.Map.Entry Interface
A Map.Entry has: 2 variables Object: key Object: value accessors for getting key & value mutator for setting value

8 Ex: HashMap vs. TreeMap Both are maps Both classes implement Map
both have the same methods Underlying data structures are different HashMap is a hash table TreeMap is a red-black tree a self-balancing binary search tree

9 So what are we using maps for?
Storing our Airports a lookup dictionary Why? because we have a lot of data fast way of getting this info

10 Our updated AirportGraph
public class AirportGraph { // THESE ARE THE NODES IN THE GRAPH public TreeMap<String,Airport> vertices = new TreeMap<String,Airport>(); // THESE ARE THE CONNECTIONS BETWEEN THE NODES // FOR EACH AIRPORT CODE, WE HAVE A SORTED Vector // OF THE ADJACENT AIRPORT CODES public TreeMap<String,Vector<String>> edges = new TreeMap<String,Vector<String>>();

11 How might we find a shortest path?
This is a bonus part of the assignment We can do this by remembering shortest paths to other nodes Let’s do another example

12 Depth First Search vs. Breadth First Search
Again, let’s do an example


Download ppt "CSE 214 – Computer Science II Maps"

Similar presentations


Ads by Google