Suppose you needed to organize a collection of telephone numbers for a company d
ID: 3535836 • Letter: S
Question
Suppose you needed to organize a collection of telephone numbers for a company division. There are currently about
6, 000 employees, and you know that the phone switch can handle at most 10, 000 phone numbers. You expect several hundred lookups against the collection every day. Would you use an array or a list to store the information? Explain.
Suppose you write a program that models a card deck. Cards are taken from the top of the deck and given out to the players. As cards are returned to the deck, they are placed on the bottom of the deck. Would you store the cards in a stack or a queue? Explain.
Explanation / Answer
Your second answer.
Yes, you would go for an array. Reason is
Arrays permit efficient (constant time) random access. So it will be easier to access the elements of the directory. Consequently, arrays are most appropriate for storing a fixed amount of data which will be accessed in an unpredictable fashion. Here we know that in worse case, the limit is not going to exceed 10000. So we know the limit. Array is the best choice for us.
Another advantage of arrays that has become very important on modern architectures is that iterating through an array has good locality of reference, and so is much faster than iterating through (say) a linked list of the same size, which tends to jump around in memory. However, an array can also be accessed in a random way, as is done with large hash tables, and in this case this is not a benefit.
Arrays also are among the most compact data structures; storing 100 integers in an array takes only 100 times the space required to store an integer, plus perhaps a few bytes of overhead for the whole array. Any pointer-based data structure, on the other hand, must keep its pointers somewhere, and these occupy additional space. This extra space becomes more significant as the data elements become smaller. For example, an array of ASCII characters takes up one byte per character, while on a 32-bit platform, which has 4-byte pointers, a linked list requires at least five bytes per character. Conversely, for very large elements, the space difference becomes a negligible fraction of the total space.
Because arrays have a fixed size, there are some indexes which refer to invalid elements.
In short, here we have to add elements and do several 100s of lookup. This is the ideal condition. Array is best suited for this.
Don't fogret to rate.
Cheers!!!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.