解释数据*结构*和数据*类型*之间的区别 [英] Explain the difference between a data *structure* and a data *type*

查看:28
本文介绍了解释数据*结构*和数据*类型*之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然试图回答 复合数据类型和数据结构有什么区别?我意识到虽然我很清楚什么是数据类型,但它不是一回事作为数据结构,我无法用语言表达差异.如果您正在教授 CS 入门课程,您会如何解释其中的区别?

While trying to answer What is the difference between a composite data type and a data structure? I realized that while I have a clear idea of what a data type is, and how it is not the same thing as a data structure, I cannot put the difference into words. If you were teaching an intro CS course, how would you explain the difference?

推荐答案

数据结构是一种对数据组织方式的抽象描述,以允许对其进行有效的某些操作.例如,二叉树是一种数据结构,斐波那契堆、AVL 树或跳过列表也是如此.理论家描述数据结构并证明它们的性质,以表明在某些假设下可以有效地解决某些算法或问题.

A data structure is an abstract description of a way of organizing data to allow certain operations on it to be performed efficiently. For example, a binary tree is a data structure, as is a Fibonacci heap, AVL tree, or skiplist. Theoreticians describe data structures and prove their properties in order to show that certain algorithms or problems can be solved efficiently under certain assumptions.

数据类型是一个(可能是无限的)具体对象类,它们都共享某些属性.例如,integer"是包含所有无穷多个整数的数据类型,string"是包含所有无穷多个字符串的数据类型,32-bit integer"是包含所有可以用 30 表示的整数的数据类型.- 两位.不要求数据类型是语言中的原始类型 - 例如,在 C++ 中,类型 int 是原始类型,如下所示:

A data type is a (potentially infinite) class of concrete objects that all share some property. For example, "integer" is a data type containing all of the infinitely many integers, "string" is a data type containing all of the infinitely many strings, and "32-bit integer" is a data type containing all integers expressible in thirty-two bits. There is no requirement that a data type be a primitive in a language - for example, in C++, the type int is a primitive, as is this one:

struct MyStruct {
    int x, y;
};

在这种情况下,MyStruct 是一种数据类型,表示标记为 MyStruct 的所有可能对象,其中有两个标记为 intxy.

In this case, MyStruct is a data type representing all possible objects labeled MyStruct that have two ints in them labeled x and y.

可以有一种数据类型来表示数据结构的所有可能实例.例如,您可以使用以下数据类型对二叉搜索树进行编码:

It is possible to have a data type representing all possible instances of a data structure. For example, you could encode a binary search tree with this data type:

struct BST {
    int data;
    BST* left, *right;
};

简而言之,数据结构是一个数学对象,具有一些属性集,可以通过多种不同方式实现为数据类型.数据类型 只是一类可以具体构造和表示的值.

In short, a data structure is a mathematical object with some set of properties that can be realized in many different ways as data types. A data type is just a class of values that can be concretely constructed and represented.

这篇关于解释数据*结构*和数据*类型*之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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