You started on the homepage, then went to the lectures page, then to the notes for lecture 14. **Task:** Assume you are browsing the CS200 website. Which one should they work on next? Where is it in the list? The cook is ready to prepare the next meal. Where should that meal be placed within the list?Ģ. **Task:** Assume the restaurant has two meals waiting to be prepared:ġ. Let's look at the differences in how lists are used in these settings. A web browser could use a list to track the order in which you visited pages. A fast-food restaurant could use a list to manage the order in which to prepare customers' meals. In practice, however, there are **different orderings themselves** that are useful in different situations. In general, lists are a flexible and valuable data structure for maintaining linear order among items. In short, neither proposed alternative offers any benefits. Thus, `ArrayLists` offer no benefits, whereas `LinkedLists` provide fast support for the operations that we do care about. These lists are not of fixed size, and we never get items from those lists by position (the two benefits of `ArrayLists`). New `KVPairs` get added to and removed from the lists within the array slots every time a user adds or removes items from the hashmap. If we replaced the array with a `LinkedList`, we would not have a constant-time way to get from an index (for a key) to the list of pairs that contains that key.Ģ. Achieving constant-time requires that we get from a key to the corresponding list of `KVPair` in constant time. Hashmaps provide constant-time access to values. :::spoiler Check your answers (after working on the task)ġ. *Note that this is a good review question for the midterm, as it checks your understanding of each of linked lists, array lists, and hashmaps.* What do we use `LinkedLists` instead of `ArrayLists` within the array? What would be the positive and negative tradeoffs for making that change? Why do we use an `array` for the outer organization of lists-of-`KVpair`? Could we replace that with a `LinkedList` instead? What would be the positive and negative tradeoffs for doing so?Ģ. Talk through the following questions about this configuration:ġ. **Task:** The hashmap implementation from lecture and homework uses an array of linked lists to organize the `KVPairs`. When you are developing programs, you choose between these based on the frequency with which you'll perform key list operations. We've looked at `LinkedList` vs `ArrayList`, where the differences are about the runtime of key operations. # Managing Different Orderings within Lists
0 Comments
Leave a Reply. |