BST vs Hash Map Trade-offs for Ordered Data
📖 Scenario: Imagine you are managing a small library's book collection. You want to store book titles and their number of copies. You need to quickly find how many copies a book has, but sometimes you also want to see all books sorted by title.
🎯 Goal: You will create a simple data structure to store books and their copies. Then, you will add a way to get all books sorted by title. This will help you understand when to use a Binary Search Tree (BST) or a Hash Map for storing ordered data.
📋 What You'll Learn
Create a JavaScript object called
bookCopies with exact book titles as keys and their copies as values.Create a variable called
sortedTitles to hold the sorted list of book titles.Use a method to get all book titles from
bookCopies and sort them alphabetically.Print the sorted list of book titles.
💡 Why This Matters
🌍 Real World
Libraries, stores, and many apps need to store items with quick lookup and sometimes sorted order for display.
💼 Career
Understanding when to use hash maps or trees helps in building efficient software for searching and sorting data.
Progress0 / 4 steps