BST vs Hash Map Trade-offs for Ordered Data
📖 Scenario: Imagine you are managing a small library system. You want to store book titles and their number of copies. You want to quickly find how many copies a book has, but also sometimes list books in alphabetical order.
🎯 Goal: You will create a simple data structure using a JavaScript object (hash map) and a sorted array (to simulate BST behavior) to understand the trade-offs between fast lookup and ordered data.
📋 What You'll Learn
Create a hash map object called
bookCopies with given book titles and copiesCreate a sorted array called
sortedBooks containing the book titles in alphabetical orderWrite a function
getCopiesFromMap that takes a book title and returns copies from the hash mapWrite a function
listBooksInOrder that returns the sorted list of book titlesPrint the number of copies for a specific book using
getCopiesFromMapPrint the list of books in alphabetical order using
listBooksInOrder💡 Why This Matters
🌍 Real World
Libraries, inventory systems, and many apps need to store data for quick lookup and sometimes in order for reports or display.
💼 Career
Understanding these trade-offs helps software developers choose the right data structure for performance and functionality.
Progress0 / 4 steps