GRE CS: Which data structure would be most appropriate to implement a collection of values with the following three characteristics?
- Items are retrieved and removed from the collection in
FIFO - There is no a-priori limit on the number of items in the
collection. - The size of an item is large relative to the storage
required for a memory address.
This was a multiple-choice question with these answers:
- (A) Singly-linked list, with head and tail pointers
- (B) Doubly-linked list, with only a head pointer
- (C) Array
- (D) Binary tree
- (E) Hash table
I think (C), (D) and (E) are wrong.
Adoes seem to be the correct answer. Because items are removed in FIFO you will only ever need to operate on the first and last element in the collection. A, C and E all allow this in constant time.There is no limit on the number of items. This means that C and E are no longer as good as A because you will eventually need to re-size an array or hash table as it gets large or allocate far more than you need to start. With a linked list you can easily add as you go.
The size of an item is large. This only further goes to suggest that A is correct because the addition of the link addresses in the storage structure will be unimportant.