Answered Questions

  • Data Structure for one million named objects

    If you have one million named objects and you want to store them in a data structure that lets you insert new objects quickly and search for an object by name quickly, what data structure should you use?

    Star Read Best Answer

    Editorial / Best Answer

    hrshksh  

    • Member Since May-2010 | May 9th, 2010


    It depends on the amount of primary memory one has for the process. If we can store 1 million records in primary memory, then we can very well take a hash table with a consistent hashing scheme for avoiding collisions. It will take O(1). 


    In most cases however this is not possible. In circumtances like this, there are two ways:
    B Trees or Extensible Hashing both of them have interesting time complexities.


    ptmich

    • May 28th, 2012

    You can use a hash table or an array of objects You can use an array of objects because you already know that you need to store a specified number of objects, also you can store and access objects qu...

    hrshksh

    • May 9th, 2010

    It depends on the amount of primary memory one has for the process. If we can store 1 million records in primary memory, then we can very well take a hash table with a consistent hashing scheme for av...