使用的实施类型? [英] Type of implementation used?

查看:85
本文介绍了使用的实施类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个问题我一直试图解决,但我很难掌握它的正确实现。如果我们编写一个程序来操作数千个记录,每个记录包括产品名称,类型,序列号,零售价等。在下面的每种情况下,解释您将使用哪种抽象数据类型(队列,堆栈,未排序和排序列表) ,以及哪种实现(数组或链接结构)。简要证明你的选择。



1)记录将按照存储的顺序检索。没有预先知道将处理多少记录以及如何处理。



我更喜欢未使用链接列表实现的未排序列表,因为我们不知道开头的记录数量,数据将在存储时被检索,因此它们必须链接,这也可以通过ADT如Queue或Stack进行链接,但它们使用数组实现,因此会出现内存分配问题。



2)
所有记录将在开头插入,一次,无特定顺序。它们将根据序列号非常频繁地检索。



即使在一次打印所有记录数据的情况下,也可以使用未排序列表。



3)将在需要时插入大量但未知数量的产品记录。它们很少单独检索。大多数操作都包括一次处理所有记录,例如打印所有记录。



但是这里排序和未排序的列表使用效率更高但我更喜欢未排序列表,因为它需要时间进行分类会降低效率。



你们觉得怎么样?



我尝试了什么:



我已经尝试过回答上面问题中给出的问题。

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.

2)
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.

推荐答案

列出的数据类型都与完全存储在内存中的数据相关。我在谈论他们通常实施的方式;基于任何类型的大容量存储都可以使用相同的接口进行实现,但显然,这不是你所说的。



我不喜欢知道你的记录大小;记录规模很小,成千上万的记录几乎没有,但性能问题可能很容易发挥作用,特别是那种天真的方法,例如只是存储,没有任何索引(除了简单的排序情况,但只是排序)一个标准),哈希值和桶的任何使用,没有这样的。基本上,你正在谈论O(N)时间复杂度的操作,如果你至少需要一些性能,那就不严重了。此时,您可能需要考虑数据库。



每条记录的数据量更大,如果数量增加,存储本身就会出现问题;你的RAM可能不适合所有数据。然后它开始听起来像一个数据库肯定。学习数据库怎么样?



-SA
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?

—SA


这篇关于使用的实施类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆