gpt4 book ai didi

language-agnostic - 'data structure' 和 'data type' 之间有区别吗?

转载 作者:行者123 更新时间:2023-12-04 02:07:42 26 4
gpt4 key购买 nike

在我学习的大学考试中经常出现的两个问题是:

  • 定义数据类型。分类和解释数据类型
  • 定义数据结构。分类和解释数据结构

  • 不知何故,它们不是一回事吗?
    考虑到您正在制作 Tree<E>在 java 。你会为 Tree<E> 声明你的类(class),添加方法到它和你会做的地方 Tree<String> myTree = new Tree<>();制作一个树对象。

    您的数据“结构”现在是数据“类型”。
    如果您被问到一个问题,请说: 变量 myTree 是什么类型的? 答案是, Tree<E> .您的数据“结构”现在是数据“类型”。

    现在,由于它们是相同的,因此它们将根据您要对其进行分类的基础以相同的方式进行分类。原始或非原始。同质或异质。线性或分层。

    这是我的理解。理解错了吗?

    最佳答案

    我想更正以下开始 - 您创建了 类(class) 称为“树”和 对象 称为“myTree”,而不是 变量 称为 的“myTree”数据类型 “树”。这些是不同的东西。

    以下是数据类型的定义:

    A data type or simply type is a classification identifying one of various types of data, such as real-valued, integer or Boolean, that determines the possible values for that type; the operations that can be done on values of that type; the meaning of the data; and the way values of that type can be stored.



    现在, as per Wikipedia ,数据类型中的“类型”有多种定义。

    你问的问题很好。当今现代语言中有一些数据类型,称为 。抽象数据类型 或简称 ADT。 ADT的定义是:

    An abstract data type (ADT) is a mathematical model for a certain class of data structures that have similar behavior; or for certain data types of one or more programming languages that have similar semantics. An abstract data type is defined indirectly, only by the operations that may be performed on it and by mathematical constraints on the effects (and possibly cost) of those operations.



    还写到:

    Abstract data types are purely theoretical entities, used (among other things) to simplify the description of abstract algorithms, to classify and evaluate data structures, and to formally describe the type systems of programming languages. However, an ADT may be implemented by specific data types or data structures, in many ways and in many programming languages; or described in a formal specification language.



    这意味着可以使用数据类型或数据结构来实现 ADT。

    至于 数据结构 :

    A data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently.



    许多教科书交替使用这些词。对于更复杂的类型,这可能会导致困惑。

    举个小例子:使用 b-tree 实现数据库是一种标准。这意味着,我们知道这种类型的 ADT 非常适合这种类型的问题,并且可以更有效地处理它。但是,为了在 ADT 中注入(inject)这种有效性,您需要创建一个数据结构来为您提供所需的输出。

    另一个例子:有很多树,如b-tree、二叉搜索树、AA树等。所有这些本质上都是树的类型,但每一棵树都有自己的数据结构。

    引用: List of data structures获取大量可用结构。

    关于language-agnostic - 'data structure' 和 'data type' 之间有区别吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18940961/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com