Design a Data Structure for Fast Group Retrieval over 1 Million Objects
viaLeetCode
Requirements: Given 1 million objects, each with 3-4 properties, choose a data structure to store all records such that a query retrieving a group of records (matching on one or more properties) executes as fast as possible.
Design: Discuss indexing each queryable property (e.g. hashmaps or sorted structures keyed by each property, or a composite index), grouping objects by the property used for group-retrieval so a lookup returns the whole bucket directly in O(1)/O(log n) rather than scanning all 1M objects. Tradeoffs: memory overhead of maintaining multiple indices vs. query speed, and how to keep secondary indices in sync when objects are inserted/updated.
asked …