Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Explain the difference between a data *structure* and a data *type* [closed]

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?

like image 336
zwol Avatar asked Jan 07 '11 21:01

zwol


People also ask

What is the difference between data structure and data type?

A Data type is one of the forms of a variable to which the value can be assigned of a given type only. This value can be used throughout the program. A Data structure is a collection of data of different data types. This collection of data can be represented using an object and can be used throughout the program.

What is the difference between data type abstract data type and data structure?

1: The relationship between data items, abstract data types, and data structures. The ADT defines the logical form of the data type. The data structure implements the physical form of the data type. Users of an ADT are typically programmers working in the same language as the implementer of the ADT.

What is data structure and types of data structure?

Data structure is a storage that is used to store and organize data. It is a way of arranging data on a computer so that it can be accessed and updated efficiently. Depending on your requirement and project, it is important to choose the right data structure for your project.

What are the different data types and data structures in Python?

Among the immutable basic data types/structures are bool , int , float , complex , str , tuple , range , frozenset , and bytes . The mutable counterparts of frozenset and bytes are set and bytearray respectively. Among the other mutable data structures are list and dict .


3 Answers

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.

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;
};

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.

like image 189
templatetypedef Avatar answered Oct 11 '22 12:10

templatetypedef


Data type can't be reduced anymore, while a data structure can, as it consists of multiple fields of different data.

However, most likely, I would use an analogy - a data type is an atom, while data structures are molecules. (yes, I know, atoms can be split etc, but the analogy should hold up for the purpose).

like image 41
Femaref Avatar answered Oct 11 '22 10:10

Femaref


data type is any type including the base types likes int but also extending to structures. structures are always made up of base types and/or other structures.

So int is a datatype but not a structure. Whereas struct point { int x; int y; } is both a structure and a datatype.

like image 4
jun Avatar answered Oct 11 '22 11:10

jun