Abstract data type vs Data Type vs Data Structure, with respect to object-oriented programming
Asked Answered
E

5

12

It is my understanding that a data structure is essentially a blueprint which contains all the information necessary to create a final product according to its specification, and a data type is a physical implementation or realization of that design (quite similar to the difference between a genotype and phenotype, from biology).

When it comes to object-oriented oriented programming, would it be accurate to say that an abstract class or interface is a data structure, because it contains a set of values and declared behaviors, and that a class which implements that abstract class or interface is a data type, because it is a concrete manifestation of those behaviors?

If this is the case, then what about the distinction between an abstract data type (ADT) and a data type? Are they truly distinct, or is ADT just colloquially shortened to 'data type'?

I ask this because it has seemed to me that these terms are often used interchangeably in conversation, and it made me wonder if my understanding was incorrect.

Electrothermics answered 1/7, 2014 at 16:48 Comment(0)
K
6

I am fairly new to answering on stackoverflow and to this sort of data structure vs data types discussion, but hopefully this helps. These links have done a lot for me in addition to what I've been taught:

Is there a difference between 'data structure' and 'data type'?

Explain the difference between a data *structure* and a data *type*

http://cs.lmu.edu/~ray/notes/dtds/

First of all, I'm going to define my usage of the word "implementation" since it seems I might be using it slightly differently than you are. I define implementation like the implementation files in C++. Such implementation contains the source code for how some interface works. For example the implementation of a singly linked list is a bunch of nodes that each contain data with a starting node that points to the next node until the last node points to some sort of null. In that sense, I can't quite say that a data type is a physical implementation of a data structure. A simplified version is that a data structure is actually the physical implementation of one or more data types. For example, a stack is a data type while a LinkedStack is a data structure that implements a stack. Although a data type can represent all possible instances of a data structure as described by the links above, not all data types have to. For example, an int is a data type, but it's not exactly the best idea to say it is a data structure.

To summarize each, please let me go in the order of data types, abstract data types, and then data structures.

Data types or types for short classify data by its values and operations. For example, if the data is 42, is 42 an int or a string? If it's an int, what int is it (what's its value)? Is it positive or negative? What kinds of operations does it have? Can I divide with it? In that sense, data types depend purely on their external behavior.

Now some data types might not specify any sort of implementation and those data types are called abstract data types. Basically, a data type is an abstract data type if the user can't access nor care about access to how the values and operations are implemented. For example, ints are abstract data types since a programmer doesn't need to know and might not care to know how ints work or how ints are added. Yet, said programmer can still work with ints, adding away to his/her content. User made data types that don't reveal its implementation would also be abstract data types. Because of this, many data types are abstract data types. In addition, abstract data types can model similar data types and data structures and be implemented by specific data types and data structures as the links above describe.

Finally data structures are ways to efficiently store data, and they are all about the implementations. For example, a singly linked list and a doubly linked list are different data structures because they have different implementations. Single linked lists only go forward whereas double linked lists can go forward and backward. I described the implementation for singly linked lists above while in short a doubly linked list's implementation is the same as a singly linked list's implementation but each node would also have a pointer to each previous node to allow the doubly linked list to go backward. The gist of data structures is that the implementation (how data is organized/stored) of a data structure is how it is distinguished.

If you want an example of the efficiency doubly linked lists have over singly linked lists, these links are nice:

When is doubly linked list more efficient than singly linked list?

https://social.msdn.microsoft.com/Forums/vstudio/en-US/270bebdb-9032-4fc1-97c6-bc017d7e0a45/when-to-use-single-linked-list-and-when-to-use-double-linked-list?forum=csharpgeneral

Otherwise, hope I was of some use and good luck.

Kitty answered 7/1, 2015 at 8:22 Comment(1)
Can you tell in simpler words difference between adt and data type. I am in sort of confusionMullis
L
4

Abstract Data Type

  • Defines contractual agreement for behavior and state management
  • Abstract Data Types exists only conceptually. They have no concrete existence in the context of a language. This is why Wikipedia refers to it specifically as a mathematical model.

Data Structure

  • Class level implementation of the contract defined by an abstract data type.

  • Data Structures exists in the form of the code that comprises your class definition.

Data Type

  • Concrete instance of a class

  • Data Types exists in the form of objects created from classes you defined.

Examples

  • A Priority Queue is an abstract data type which can be implemented with a Binary Heap data structure.

  • A List is an abstract data type that can be implemented with an array or linked list data struture

TLDR

Abstract Data Type > Data Structure > Data Type

Lynn answered 3/9, 2016 at 17:39 Comment(2)
can you give example of data type ?Mullis
var arr = [1,2,3];Lynn
P
0

A method of interpreting a bit pattern is called a data type. There are several data types such as binary integers, binary coded decimal, non-negative integers, real numbers and character strings. E.g.: a bit string 00100110 can be interpreted as the number '38' (binary coded decimal).

If we do some specific operation with data structure, then data structure with these specific operation are called Abstract Data Type. It is a tool for specifying logical properties and operation of data types.

Data Structure is the implementation of the abstract operations.

-source: books, google search....

Psid answered 25/5, 2017 at 8:50 Comment(0)
M
0

As I know about,for example,in Python,int float boolare data types,they are built-in classes,str list tuple dict set frozensetare data structures,they are also built-in classes,and we can write linked list linked stack linked queue linked deque positional list array stack array queue linked tree linked binary tree binary search tree AVL tree red black tree splay tree hash table priority queueand etc,we can call these data structure,or ADT,in my opinion,data structure/ADT is to organize data,data type is to classify data into int/float/bool/etc Python built-in list is implemented with dynamic array,Python built-intupleis implemented with static array,Python built-in`dict/set/frozrnset are implemented with hash table

Marisolmarissa answered 22/5, 2018 at 6:40 Comment(0)
E
0

Data is raw, unprocessed (and possibly) information which is to be computed by a computer.
Ex- your test marks, names of your crushes

Data Types are used to define certain "domain" and (thus) operations on Data.
Ex- integers, binary, characters

Abstract Data Types are used to define a certain "behaviour" and (thus) organisation of Data.
Ex- stacks, queues, vectors

Data Structures are concrete structure of Data, defined with domain and behaviour.
Ex- vector<int> marks, vector<string> name_crush

Endocranium answered 2/4, 2023 at 14:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.