CS173: Intro to Computer Science - HashMaps
Activity Goals
The goals of this activity are:
- To identify the key-value relationship of the
HashMap
- To use generic data types with Generic container classes
The Activity
Directions
Consider the activity models and answer the questions provided. First reflect on these questions on your own briefly, before discussing and comparing your thoughts with your group. Appoint one member of your group to discuss your findings with the class, and the rest of the group should help that member prepare their response. Answer each question individually from the activity on the Class Activity Questions discussion board. After class, think about the questions in the reflective prompt and respond to those individually in your notebook. Report out on areas of disagreement or items for which you and your group identified alternative approaches. Write down and report out questions you encountered along the way for group discussion.
Model 1: Data Maps
Questions
- Consider the dictionary and phone book above. When you look something up in each of them, what are you looking up, and what are you looking for? What are the data types?
- What are some ways that we make these lookups easier? How are the data organized, and what part of the data is organized that way?
- A phone book maps ______ to ______, and a dictionary maps ______ to ______.
- In computing, we tend to say that we map keys to values. For the phone book and dictionary, what is the key, and what is the value?
Model 2: The HashMap
Questions
- What is different about the data type that defines the
HashMap
variable in this program? What do the extra parameters mean?
- What would you change in the program above to store the number of students enrolled in each course, instead of the instructor of each course?
- What other types of data could you represent with a
HashMap
?
- Suppose you are developing a web browser that accesses web pages. You want to cache the pages, so that you only access them once, to save on I/O, network calls, and your data plan. How might a
HashMap
help you to do this? What would be the key and the value?
Model 3: A Complex HashMap
Questions
- What is
browserCache
mapping?
- What is the purpose of the additional
HashMap
?
Submission
Submit your answers to the questions using the Class Activity Questions discussion board. You may also respond to questions or comments made by others, or ask follow-up questions there. Answer any reflective prompt questions in the Reflective Journal section of your OneNote Classroom personal section.