top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

Propose a data structure for the following -

+1 vote

Propose a data structure for the following:
- The data structure would hold elements from 0 to N-1.
- There is no order on the elements (no ascending/descending order requirement)

The complexity of the operations should be as follows:
* Initialization - O(1)
* Insertion of an element - O(1)
* Deletion of an element - O(1)
* Finding a element - O(1)
* Deleting all elements - O(1)

posted Sep 23, 2014 by Aarti Jain

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
Best answer

You can use the Hashing for the given purpose, it has all the given operations Initialization, Insertion, Deletion, Search and Deletion of 0(1). In hashing we take a key and apply the hash function which tells us the location of the element.

You can google, there are many opensource implementation available in almost all language.

answer Sep 23, 2014 by Salil Agrawal
Similar Questions
+2 votes

getRandom() should pick a "random" element from your data structure, and should not be predictable (for instance always picking the "first" element from your DS)

+3 votes

Suppose we have the option of selecting Tree, Link list and Hash Table now the question is on what basis we should select each one for our use.

+4 votes

Give a good data structure for having n queues (n not fixed) in a finite memory segment. You can
have some data-structure separate for each queue. Try to use at least 90% of the memory space.

Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.