Click here to Skip to main content
15,747,189 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
There is a question that I have been trying to solve for a while but I'm having difficulty to grasp the correct implementation for it. If we write a program that will manipulate thousands of records, each comprising product name, type, serial number, retail price, etc. In each case below, explain which Abstract Data Type (Queue, Stack, Unsorted and Sorted List) you would use, and which implementation (array or linked structure). Briefly justify your choices.

1) Records will be retrieved in the same order they were stored. There is no telling in advance how many records will be processed and how.

I prefer Unsorted list for this purpose which used linked list implementation because we don't know the number of records at beginning,and data will be retrieved as they are stored hence they must be linked which can also be possible by ADT like Queue or Stack but they use array implementation hence memory allocation problem arises.

All records will be inserted at the beginning, once and in no particular order. They will be retrieved very frequently, based on serial number.

Even in the case of printing all the data of records at one time it will be possible with the Unsorted list.

3) A large but unknown number of product records will be inserted, as and when needed. They will seldom be retrieved individually. Most operations will consist of processing all records at one go e.g., printing all.

However here sorted and Unsorted list had more efficiency to use but I prefer Unsorted list because it takes time for sorting which decreases its efficiency.

What do you guys think?

What I have tried:

I have tried answering the problem as given above in the question.
Updated 27-Jun-16 10:30am
Philippe Mori 27-Jun-16 20:52pm    
You should do your homework yourself. Queue and stack can be based on array or list so your first answer is incorrect.

For the second case, it seems you haven't read the case carefully enough. It explicitly say that items are retrieve a lot based on serial number. An unsorted list would not be efficient at all.

1 solution

The data types you list are all related to the data fully stored in memory. I'm talking of the way they are usually implemented; it's possible to use the same interfaces for the implementations based on any kind of massive storage, but, apparently, this is not what you are talking about.

I don't know your record size; with small record size, "thousands of records" is next to nothing, but the performance issues may easily come into play, especially with that naive approach, such as just storing, without any indexing (except trivial case of sorting, but sorting by only one criteria), any use of hash values and buckets, nothing like that. Basically, you are talking about something with the operations of O(N) time complexity, which is just not serious if you need at least some performance. At this point, you already may need to think in terms of databases.

And with greater data amount per record, and if the volumes grow, the storage itself becomes problematic; your RAM may not fit all data. Then it starts to sound like a database quite certainly. How about learning databases?

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900