4.3. Linked Bags¶
4.3.1. Objectives¶
Upon completion of this module, students will be able to:
Name the function and purpose of basic Java data structures
State key characteristics of Bags in Java
Build and populate Bags in Java
4.3.1.1. Suggested Reading:¶
Chapter 3: Bag Implementation That Links Data from Data Structures and Abstractions with Java, 4th edition by Frank M. Carrano and Timothy Henry
4.3.2. Interactive: Introduction to Linked Bags¶
Follow Along and Engage
LinkedBagIntro.pdfDownload the slides corresponding to the video. Take notes on them as you watch the video, practice drawing diagrams yourself!
4.3.3. Interactive: LinkedBag add() and toArray()¶
Follow Along and Engage
LinkedBagAddToArray.pdfDownload the slides corresponding to the video. Take notes on them as you watch the video, practice drawing diagrams yourself!
4.3.4. Checkpoint 1¶
4.3.5. Interactive: ExLinkedBagJUnit Demonstration¶
Follow Along, Practice and Explore
Download to run and explore the corresponding project from the video on your own in eclipse. The project CS2-Support is required for the sample project above. It is also used in your course projects. To download the CS2-Support you must first complete the configuration steps for your first lab. You will then be able to download it via eclipse using the blue down arrow icon or using the Project Menu and selecting “Download Assignment…”
4.3.6. Interactive: LinkedBag getFrequencyOf() and contains()¶
Follow Along and Engage
LinkedFreqContains.pdfDownload the slides corresponding to the video. Take notes on them as you watch the video, practice drawing diagrams yourself!
4.3.7. Checkpoint 2¶
4.3.8. Interactive: LinkedBag Removing an item¶
Follow Along and Engage
LinkedRemove.pdfDownload the slides corresponding to the video. Take notes on them as you watch the video, practice drawing diagrams yourself!
Tradeoffs of using a linked chain implementation for a bag
Pros |
Cons |
---|---|
Bag can grow in size easily |
Requires more space than a same-sized array |
Adding an entry to the bag is fast |
Removing a specified entry requires time to locate the entry |
4.3.9. Checkpoint 3¶
4.3.10. Wrapping up Bags¶
As you’ve seen, Bags are a simple but foundational data structure in Java. We will continue with other data structures and their unique characteristics, including opportunities to practice building them, in later modules.
Recall that the objectives for this module were to:
Name the function and purpose of basic Java data structures
State key characteristics of Bags in Java
Build and populate Bags in Java