GeekInterview.com
Series: Subject: Topic:
Question: 57 of 246

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?
Asked by: bitsbyter | Member Since Sep-2008 | Asked on: Sep 17th, 2008

View all questions by bitsbyter

Editorial / Best Answer

Answered by: hrshksh

View all answers by hrshksh

Member Since May-2010 | Answered On : 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.


Showing Answers 1 - 10 of 10 Answers
Hemantgupta83

Answered On : Sep 20th, 2008

View all answers by Hemantgupta83

Binary tree

Yes  1 User has rated as useful.
  
Login to rate this answer.
skmandowara

Answered On : Sep 23rd, 2008

View all answers by skmandowara

One Million Named Objects:

1. I dont think binary Tree is a good idea. Depth of the tree will be huge
2. B+ Tree is the right Data structure

Yes  4 Users have rated as useful.
  
Login to rate this answer.

Since the objects are named, I would go for the hash table.

  
Login to rate this answer.

I think the most suitable here will be a dictionary solution - the
tree where each node contains a letter. And each name will be a word
in such a dictionary, so we need the node also contains the sign that
there is a name ends here (let's say -|). For example:


N  | M | ...

I | O I | ...

K-| | L K-| | ...

| L | ...


| Y-| | ...


  
Login to rate this answer.
nirmo420

Answered On : Apr 3rd, 2009

View all answers by nirmo420

Since there is the question about serching and insertion quickly, i think the data structure should be binary serach tree , not simple binary tree

  
Login to rate this answer.
vinod148

Answered On : Oct 23rd, 2009

View all answers by vinod148

The ultimate solution for this is TRIE or advanced TRIE

Yes  3 Users have rated as useful.
  
Login to rate this answer.

AVL trees

  
Login to rate this answer.
animeshkhare

Answered On : Mar 5th, 2010

View all answers by animeshkhare

B tree will be most suitable.  B+ is not because the requirement is not sequential search.

Yes  2 Users have rated as useful.
  
Login to rate this answer.
hrshksh

Answered On : May 9th, 2010

View all answers by hrshksh

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.


  
Login to rate this answer.
ptmich

Answered On : May 28th, 2012

View all answers by ptmich

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 quickly in an array of objects. First declare the object:

Code
  1.  
  2. GradeBook myGradeBook = new Gradebook();
  3.  
  4. Then create array to contain objects (gradebooks):
  5.  
  6. GradeBook arrayOfObjects[] = new GradeBook[1,000,000];

  
Login to rate this answer.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Ads

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.