most recent 30 from stackoverflow.com2026-05-01T11:47:42Zhttps://stackoverflow.com/feeds/question/10267084https://creativecommons.org/licenses/by-sa/4.0/rdfhttps://stackoverflow.com/q/1026708472Tommy2014https://stackoverflow.com/users/13214762012-04-22T10:13:38Z2023-12-28T16:13:50Z
<p>I am currently learning about Abstract Data Types (ADTs), but I do not get the concept at all. Could someone please explain to me what this actually is? Also, what are collection, bag, and List ADTs? In simple terms?</p>
https://stackoverflow.com/questions/10267084/-/11821915#1182191523Bill the Lizardhttps://stackoverflow.com/users/12882012-08-06T02:33:36Z2012-08-25T18:26:51Z<p>The <a href="http://en.wikipedia.org/wiki/Abstract_data_type" rel="noreferrer">Abstact data type</a> Wikipedia article has a lot to say.</p>
<blockquote>
<p>In computer science, 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.</p>
</blockquote>
<p>In slightly more concrete terms, you can take Java's <a href="http://docs.oracle.com/javase/6/docs/api/java/util/List.html" rel="noreferrer"><code>List</code></a> interface as an example. The interface doesn't explicitly define any behavior at all because there is no concrete <code>List</code> class. The interface only defines a set of methods that other classes (e.g. <a href="http://docs.oracle.com/javase/6/docs/api/java/util/ArrayList.html" rel="noreferrer"><code>ArrayList</code></a> and <a href="http://docs.oracle.com/javase/6/docs/api/java/util/LinkedList.html" rel="noreferrer"><code>LinkedList</code></a>) must implement in order to be considered a <code>List</code>.</p>
<p>A <strong>collection</strong> is another abstract data type. In the case of Java's <a href="http://docs.oracle.com/javase/6/docs/api/java/util/Collection.html" rel="noreferrer"><code>Collection</code></a> interface, it's even more abstract than <code>List</code>, since </p>
<blockquote>
<p>The <code>List</code> interface places additional stipulations, beyond those specified in the <code>Collection</code> interface, on the contracts of the <code>iterator</code>, <code>add</code>, <code>remove</code>, <code>equals</code>, and <code>hashCode</code> methods.</p>
</blockquote>
<p>A <strong>bag</strong> is also known as a <a href="http://en.wikipedia.org/wiki/Multiset" rel="noreferrer">multiset</a>.</p>
<blockquote>
<p>In mathematics, the notion of multiset (or bag) is a generalization of the notion of set in which members are allowed to appear more than once. For example, there is a unique set that contains the elements a and b and no others, but there are many multisets with this property, such as the multiset that contains two copies of a and one of b or the multiset that contains three copies of both a and b.</p>
</blockquote>
<p>In Java, a Bag would be a collection that implements a very simple interface. You only need to be able to add items to a bag, check its size, and iterate over the items it contains. See <a href="http://algs4.cs.princeton.edu/13stacks/Bag.java.html" rel="noreferrer">Bag.java</a> for an example implementation (from Sedgewick & Wayne's <a href="http://algs4.cs.princeton.edu/10fundamentals/" rel="noreferrer">Algorithms 4th edition</a>).</p>
https://stackoverflow.com/questions/10267084/-/20511075#205110751purushottam ROYhttps://stackoverflow.com/users/30896512013-12-11T05:16:55Z2013-12-11T05:16:55Z<p>ADT are a set of data values and associated operations that are precisely independent of any paticular implementaition. The strength of an ADT is implementaion is hidden from the user.only interface is declared .This means that the ADT is various ways </p>
https://stackoverflow.com/questions/10267084/-/28927411#289274110Ashish Jainhttps://stackoverflow.com/users/46467872015-03-08T14:14:21Z2015-03-08T14:14:21Z<p>Simply Abstract Data Type is nothing but a set of operation and set of data is used for storing some other data efficiently in the machine.
There is no need of any perticular type declaration.
It just require a implementation of ADT. </p>
https://stackoverflow.com/questions/10267084/-/31113335#31113335148Premrajhttps://stackoverflow.com/users/16970992015-06-29T10:27:16Z2023-12-28T16:13:50Z<p>Abstract Data Type(ADT) is a data type, where only behavior is defined but not implementation.</p>
<p>Opposite of ADT is Concrete Data Type (CDT), where it contains an implementation of ADT.</p>
<p><strong>Examples:</strong><br />
<code>List, Map, Queue, Set, Stack, Table, Tree, and Vector</code> are ADTs. Each of these ADTs has many implementations i.e. CDT. The container is a high-level ADT of above all ADTs.</p>
<p><strong>Real life example:</strong><br />
book is Abstract (Telephone Book is an implementation)</p>
<p><img src="https://i.sstatic.net/VESaU.jpg" alt="enter image description here" /></p>
https://stackoverflow.com/questions/10267084/-/40249771#402497713Deehttps://stackoverflow.com/users/70719142016-10-25T21:10:45Z2016-10-25T21:10:45Z<p>A truly abstract data type describes the properties of its instances without commitment to their representation or particular operations. For example the abstract (mathematical) type Integer is a discrete, unlimited, linearly ordered set of instances. A concrete type gives a specific representation for instances and implements a specific set of operations. </p>
https://stackoverflow.com/questions/10267084/-/40722978#407229781user7189947https://stackoverflow.com/users/71899472016-11-21T14:51:47Z2016-11-21T14:51:47Z<p>Abstract Data type is a mathematical module that includes data with various operations. Implementation details are hidden and that's why it is called abstract. Abstraction allowed you to organise the complexity of the task by focusing on logical properties of data and actions.</p>
https://stackoverflow.com/questions/10267084/-/42787408#427874080cammandohttps://stackoverflow.com/users/52300442017-03-14T13:31:21Z2017-03-14T13:31:21Z<p>To solve problems we combine the data structure with their operations. An ADT consists of two parts:</p>
<ol>
<li>Declaration of Data.</li>
<li>Declaration of Operation.</li>
</ol>
<p>Commonly used ADT's are Linked Lists, Stacks, Queues, Priority Queues, Trees etc. While defining ADTs we don't need to worry about implementation detals. They come into picture only when we want to use them.</p>
https://stackoverflow.com/questions/10267084/-/44009764#440097641Alcino Dall'Igna Jr.https://stackoverflow.com/users/80216172017-05-16T19:14:32Z2017-05-16T19:14:32Z<p>In programming languages, a type is some data and the associated operations. An ADT is a user defined data aggregate and the operations over these data and is characterized by <strong>encapsulation</strong>, the data and operations are represented, or at list declared, in a single syntactic unit, and <strong>information hiding</strong>, only the relevant operations are visible for the user of the ADT, the ADT <strong>interface</strong>, in the same way that a normal data type in the programming language. It's an abstraction because the internal representation of the data and implementation of the operations are of no concern to the ADT user.</p>
https://stackoverflow.com/questions/10267084/-/44275454#442754540garghttps://stackoverflow.com/users/59565682017-05-31T04:07:24Z2017-05-31T04:07:24Z<p><strong>Abstract data type</strong> are like user defined data type on which we can perform functions without knowing what is there inside the datatype and how the operations are performed on them . As the information is not exposed its abstracted. eg. List,Array, Stack, Queue. On Stack we can perform functions like Push, Pop but we are not sure how its being implemented behind the curtains.</p>
https://stackoverflow.com/questions/10267084/-/47496481#474964810Ibukun Muyidehttps://stackoverflow.com/users/22157382017-11-26T13:08:52Z2017-11-26T13:08:52Z<p>ADT is a set of objects and operations, no where in an ADT’s definitions is there any mention of how the set of operations is implemented. Programmers who use collections only need to know how to instantiate and access data in some pre-determined manner, without concerns for the details of the collections implementations. In other words, from a user’s perspective, a collection is an abstraction, and for this reason, in computer science, some collections are referred to as abstract data types (ADTs). The user is only concern with learning its interface, or the set of operations its performs...<a href="http://www.algorithmhub.online/2017/09/abstract-data-types-adts.html" rel="nofollow noreferrer">more</a></p>
https://stackoverflow.com/questions/10267084/-/47952087#479520875coding_ninzahttps://stackoverflow.com/users/82956412017-12-23T11:28:20Z2017-12-23T11:28:20Z<h1><strong>Notation of Abstract Data Type(ADT)</strong></h1>
<blockquote>
<p>An abstract data type could be defined as a mathematical model with a
collection of operations defined on it. A simple example is the set of
integers together with the operations of union, intersection defined
on the set.</p>
<p>The <strong>ADT's</strong> are generalizations of primitive data type(integer, char
etc) and they encapsulate a data type in the sense that the definition
of the type and all operations on that type localized to one section
of the program. They are treated as a primitive data type outside the
section in which the <strong>ADT</strong> and its operations are defined.</p>
<p>An implementation of an <strong>ADT</strong> is the translation into statements of
a programming language of the declaration that defines a variable to
be of that <strong>ADT</strong>, plus a procedure in that language for each
operation of that <strong>ADT</strong>. The implementation of the ADT chooses a
data structure to represent the <strong>ADT</strong>.</p>
<p>A useful tool for specifying the logical properties of data type is
the abstract data type. Fundamentally, a data type is a collection of
values and a set of operations on those values. That collection and
those operations form a mathematical construct that may be implemented
using a particular hardware and software data structure. The term
<strong>"abstract data type"</strong> refers to the basic mathematical concept that defines the data type.</p>
<p>In defining an abstract data type as mathamatical concept, we are not
concerned with space or time efficinecy. Those are implementation
issue. Infact, the defination of <strong>ADT</strong> is not concerned with
implementaion detail at all. It may not even be possible to implement
a particular <strong>ADT</strong> on a particular piece of hardware or using a
particular software system. For example, we have already seen that an
<strong>ADT</strong> integer is not universally implementable.</p>
<p>To illustrate the concept of an <strong>ADT</strong> and my specification method,
consider the <strong>ADT RATIONAL</strong> which corresponds to the mathematical
concept of a rational number. A rational number is a number that can
be expressed as the quotient of two integers. The operations on
rational numbers that, we define are the creation of a rational number
from two integers, addition, multiplication and testing for equality.
The following is an initial specification of this <strong>ADT</strong>.</p>
</blockquote>
<pre><code> /* Value defination */
abstract typedef <integer, integer> RATIONAL;
condition RATIONAL [1]!=0;
/*Operator defination*/
abstract RATIONAL makerational (a,b)
int a,b;
preconditon b!=0;
postcondition makerational [0] =a;
makerational [1] =b;
abstract RATIONAL add [a,b]
RATIONAL a,b;
postcondition add[1] = = a[1] * b[1]
add[0] = a[0]*b[1]+b[0]*a[1]
abstract RATIONAL mult [a, b]
RATIONAL a,b;
postcondition mult[0] = = a[0]*b[a]
mult[1] = = a[1]*b[1]
abstract equal (a,b)
RATIONAL a,b;
postcondition equal = = |a[0] * b[1] = = b[0] * a[1];
</code></pre>
<blockquote>
<p>An <strong>ADT</strong> consists of two parts:-</p>
<p><strong>1) Value definition</strong></p>
<p><strong>2) Operation definition</strong></p>
</blockquote>
<h3>1) Value Definition:-</h3>
<blockquote>
<p>The value definition defines the collection of values for the ADT and
consists of two parts:</p>
<p><strong>1) Definition Clause</strong></p>
<p><strong>2) Condition Clause</strong></p>
<p>For example, the value definition for the <strong>ADT</strong> RATIONAL states that
a RATIONAL value consists of two integers, the second of which does
not equal to 0.</p>
<p>The keyword abstract typedef introduces a value definitions and the
keyword condition is used to specify any conditions on the newly
defined data type. In this definition the condition specifies that the
denominator may not be 0. The definition clause is required, but the
condition may not be necessary for every <strong>ADT</strong>.</p>
</blockquote>
<h3>2) Operator Definition:-</h3>
<blockquote>
<p>Each operator is defined as an abstract junction with three parts.</p>
<p><strong>1)Header</strong></p>
<p><strong>2)Optional Preconditions</strong></p>
<p><strong>3)Optional Postconditions</strong></p>
<p>For example the operator definition of the ADT RATIONAL includes the
operations of creation (makerational), addition (add) and
multiplication (mult) as well as a test for equality (equal). Let us
consider the specification for multiplication first, since, it is the
simplest. It contains a header and post-conditions, but no
pre-conditions.</p>
</blockquote>
<pre><code>abstract RATIONAL mult [a,b]
RATIONAL a,b;
postcondition mult[0] = a[0]*b[0]
mult[1] = a[1]*b[1]
</code></pre>
<blockquote>
<p>The header of this definition is the first two lines, which are just
like a C function header. The keyword abstract indicates that it is
not a C function but an ADT operator definition.</p>
<p>The post-condition specifies, what the operation does. In a
post-condition, the name of the function (in this case, mult) is used
to denote the result of an operation. Thus, mult [0] represents
numerator of result and mult <a href="https://i.sstatic.net/zy0mK.jpg" rel="noreferrer">1</a> represents the denominator of the
result. That is it specifies, what conditions become true after the
operation is executed. In this example the post-condition specifies
that the neumerator of the result of a rational multiplication equals
integer product of numerators of the two inputs and the denominator
equals th einteger product of two denominators.</p>
</blockquote>
<h1>List</h1>
<blockquote>
<p>In computer science, a list or sequence is an abstract data type that
represents a countable number of ordered values, where the same value
may occur more than once. An instance of a list is a computer
representation of the mathematical concept of a finite sequence; the
(potentially) infinite analog of a list is a stream. Lists are a basic
example of containers, as they contain other values. If the same value
occurs multiple times, each occurrence is considered a distinct item</p>
<p>The name list is also used for several concrete data structures that
can be used to implement abstract lists, especially linked lists.</p>
</blockquote>
<p><a href="https://i.sstatic.net/zy0mK.jpg" rel="noreferrer"><img src="https://i.sstatic.net/zy0mK.jpg" alt="enter image description here"></a></p>
<p>Image of a List</p>
<h1>Bag</h1>
<blockquote>
<p>A bag is a collection of objects, where you can keep adding objects to
the bag, but you cannot remove them once added to the bag. So with a
bag data structure, you can collect all the objects, and then iterate
through them. You will bags normally when you program in Java.</p>
</blockquote>
<p><a href="https://i.sstatic.net/Dridm.jpg" rel="noreferrer"><img src="https://i.sstatic.net/Dridm.jpg" alt="Bag"></a></p>
<p>Image of a Bag</p>
<h1>Collection</h1>
<blockquote>
<p>A collection in the Java sense refers to any class that implements the
Collection interface. A collection in a generic sense is just a group
of objects.</p>
</blockquote>
<p><a href="https://i.sstatic.net/7506n.jpg" rel="noreferrer"><img src="https://i.sstatic.net/7506n.jpg" alt="enter image description here"></a></p>
<p>Image of collections</p>
https://stackoverflow.com/questions/10267084/-/47952309#479523091user9131165https://stackoverflow.com/users/02017-12-23T11:58:01Z2017-12-23T12:52:51Z<blockquote>
<p>Before defining <strong>abstract data types</strong>, let us considers the different
view of system-defined data types. We all know that by default all
primitive data types (int, float, etc.) support basic operations such
as addition and subtraction. The system provides the implementations
for the primitive data types. For user-defined data types, we also
need to define operations. The implementation for these operations can
be done when we want to actually use them. That means in general,
user-defined data types are defined along with their operations.</p>
<p>To simplify the process of solving problems, we combine the data
structures with their operations and we call this <strong>"Abstract Data
Type"</strong>. (ADT's). </p>
<p>Commonly used <strong>ADT'S</strong> include: Linked List, Stacks, Queues, Binary Tree,
Dictionaries, Disjoint Sets (Union and find), Hash Tables and many
others.</p>
<p><strong>ADT's</strong> consist of two types:</p>
<p><strong>1. Declaration of data.</strong></p>
<p><strong>2. Declaration of operation.</strong></p>
</blockquote>
https://stackoverflow.com/questions/10267084/-/48202691#482026910user8369850https://stackoverflow.com/users/02018-01-11T08:32:20Z2018-12-20T03:06:45Z<p>Abstract data type is the collection of values and any kind of operation on these values. For example, since String is not a primitive data type, we can include it in abstract data types.</p>
https://stackoverflow.com/questions/10267084/-/50648532#506485320Alireza Rahmani Khalilihttps://stackoverflow.com/users/20432482018-06-01T17:37:51Z2018-06-01T17:37:51Z<p><strong>in a simple word:</strong> An abstract data type is a collection of data and operations that work on that data. The operations both describe the data to the rest of the program and allow the rest of the program to change the data. The word “data” in “abstract data type” is used loosely. An ADT might be a graphics window with all the operations that affect it, a file and file operations, an insurance-rates table and the operations on it, or something else. </p>
<p><em>from code complete 2 book</em> </p>
https://stackoverflow.com/questions/10267084/-/56139806#561398060Hamza Saeedhttps://stackoverflow.com/users/115011652019-05-14T23:17:26Z2019-05-14T23:17:26Z<p>ADT is a data type in which collection of data and operation works on that data . It focuses on more the concept than implementation..
It's up to you which language you use to make it visible on the earth
Example:
Stack is an ADT while the Array is not
Stack is ADT because we can implement it by many languages,
Python c c++ java and many more , while Array is built in data type </p>
https://stackoverflow.com/questions/10267084/-/57484258#57484258-1Suraj kumarhttps://stackoverflow.com/users/119241662019-08-13T19:34:33Z2019-08-14T00:09:52Z<p>The term data type is as the type of data which a particular variable can hold - it may be an integer, a character, a float, or any range of simple data storage representation. However, when we build an object oriented system, we use other data types, known as abstract data type, which represents more realistic entities.</p>
<p>E.g.: We might be interested in representing a 'bank account' data type, which describe how all bank account are handled in a program. Abstraction is about reducing complexity, ignoring unnecessary details.</p>
https://stackoverflow.com/questions/10267084/-/63711510#637115100Adil Abbasihttps://stackoverflow.com/users/22858482020-09-02T18:23:50Z2020-09-02T18:23:50Z<p>An abstract data type, sometimes abbreviated ADT, is a logical description of how we view the data and the operations that are allowed without regard to how they will be implemented. This means that we are concerned only with what the data is representing and not with how it will eventually be constructed.</p>
<p><a href="https://runestone.academy/runestone/books/published/pythonds/Introduction/WhyStudyDataStructuresandAbstractDataTypes.html" rel="nofollow noreferrer">https://runestone.academy/runestone/books/published/pythonds/Introduction/WhyStudyDataStructuresandAbstractDataTypes.html</a></p>
https://stackoverflow.com/questions/10267084/-/64087598#640875983Yeasin Arafathhttps://stackoverflow.com/users/115597732020-09-27T10:49:16Z2020-09-27T10:49:16Z<p>Actually Abstract Data Types is:</p>
<ul>
<li>Concepts or theoretical model that defines a data type logically</li>
<li>Specifies set of data and set of operations that can be performed on that data</li>
<li>Does not mention anything about how operations will be implemented</li>
<li>"Existing as an idea but not having a physical idea"</li>
</ul>
<p>For example, lets see specifications of some Abstract Data Types,</p>
<ol>
<li>List Abstract Data Type: initialize(), get(), insert(), remove(), etc.</li>
<li>Stack Abstract Data Type: push(), pop(), peek(), isEmpty(), isNull(), etc.</li>
<li>Queue Abstract Data Type: enqueue(), dequeue(), size(), peek(), etc.</li>
</ol>
https://stackoverflow.com/questions/10267084/-/65771454#657714543Sarvar Nishonboyevhttps://stackoverflow.com/users/24900742021-01-18T09:02:03Z2021-01-18T09:02:03Z<p>One of the simplest explanation given on Brilliant's wiki:</p>
<blockquote>
<p>Abstract data types, commonly abbreviated ADTs, are a way of
classifying data structures based on how they are used and the
behaviors they provide. They do not specify how the data structure
must be implemented or laid out in memory, but simply provide a
minimal expected interface and set of behaviors. For example, a stack
is an abstract data type that specifies a linear data structure with
LIFO (last in, first out) behavior. Stacks are commonly implemented
using arrays or linked lists, but a needlessly complicated
implementation using a binary search tree is still a valid
implementation. To be clear, it is incorrect to say that stacks are
arrays or vice versa. An array can be used as a stack. Likewise, a
stack can be implemented using an array.</p>
<p>Since abstract data types don't specify an implementation, this means
it's also incorrect to talk about the time complexity of a given
abstract data type. An associative array may or may not have O(1)
average search times. An associative array that is implemented by a
hash table does have O(1) average search times.</p>
<p>Example for ADT: List - can be implemented using Array and LinkedList, Queue, Deque, Stack, Associative array, Set.</p>
</blockquote>
<p><a href="https://brilliant.org/wiki/abstract-data-types/?subtopic=types-and-data-structures&chapter=abstract-data-types" rel="nofollow noreferrer">https://brilliant.org/wiki/abstract-data-types/?subtopic=types-and-data-structures&chapter=abstract-data-types</a></p>
https://stackoverflow.com/questions/10267084/-/67496478#674964780Sundar Gautamhttps://stackoverflow.com/users/106909922021-05-12T02:08:16Z2021-05-12T02:08:16Z<p>Abstractions give you only information(service information) but not implementation.
For eg: When you go to withdraw money from an ATM machine, you just know one thing i.e put your ATM card to the machine, click the withdraw option, enter the amount and your money is out if there is money.
This is only what you know about ATM machines. But do you know how you are receiving money?? What business logic is going on behind? Which database is being called? Which server at which location is being invoked?? No, you only know is service information i.e you can withdraw money. This is an abstraction.</p>
<p>Similarly, ADT gives you an overview of data types: what they are / can be stored and what operations you can perform on those data types. But it doesn’t provide how to implement that. This is ADT. It only defines the logical form of your data types.</p>
<p>Another analogy is :
In a car or bike, you only know when you press the brake your vehicle will stop. But do you know how the bike stops when you press the brake??? No, means implementation detail is being hidden. You only know what brake does when you press but don’t know how it does.</p>
https://stackoverflow.com/questions/10267084/-/72294486#722944861Mosharof Hossenhttps://stackoverflow.com/users/168451212022-05-18T18:45:53Z2022-06-09T11:04:51Z<p>An abstract data type(<strong>ADT</strong>) is an abstraction of a data structure that provides only the interface to which the data structure must adhere. The interface does not give any specific details about how something should be implemented or in what programming language.</p>
<p><img src="https://i.sstatic.net/3wv1c.png" alt="image" /></p>