3

Stack is called as abstract data type, which is nothing but an interface.Then why stack comes under data structures topic.Is this a data structure or abstract data type?Is both are same or different?

user1849655
  • 53
  • 1
  • 1
  • 6

4 Answers4

6

From Wikipedia:

Abstract data types are purely theoretical entities, used (among other things) to simplify the description of abstract algorithms, to classify and evaluate data structures

In computer science, a data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently

One way of describing the stack is as a last in, first out (LIFO) abstract data type and linear data structure. A stack can have any abstract data type as an element, but is characterized by two fundamental operations, called push and pop (or pull).

So, it can be concluded that Abstract Data Types are theoretical but when realized are called data structures.

To be more clear:

A data type can be considered abstract when it is defined in terms of operations on it, and its implementation is hidden (so that we can always replace one implementation with another for, e.g., efficiency reasons, and this will not interfere with anything in the program).

Community
  • 1
  • 1
Azodious
  • 13,752
  • 1
  • 36
  • 71
  • 1
    Stack is abstract data type because it hides how it is implemented like using array or linked list.But it organizes data for efficient management and retrieval so it a data structure also.Am I taking it in the right way? – user1849655 Dec 28 '12 at 11:48
0

Stack is a abstract data type and it is also called linear data structure.It follows last in, first out (LIFO) strategy.so its a part of data structure...

coder
  • 1,980
  • 3
  • 21
  • 32
0

An abstract data type (ADT) is a theoretical set of specifications of a data set and the set of operations that can be performed on the data within a set. A data type is termed abstract when it is independent of various concrete implementations.

let's say Integer supports addition, multiplication,division operations.

These operations won't work on String data since they cannot support multiplication.hence Integer is not ADT.

now u get the point,

If your operations on data types don't care about the type of data its called Abstract Data Structure.e.g Stack,list,queue…here these things supports operations like push(),pop(),add(),delete() Not caring about what we push,pop,delete.

Here depending upon the type of Implementation (List,Stack,Queue) we get to decide how those ADT are managed.

Why Stack is abstract data type?

`Stack s = new Stack<>();
List l = new LinkedList<>();
s.push(45);
s.push("str");
//s.push("String");
if(s.peek().equals(45)){
    System.out.println("Treu");
}`

I don't think any more explanation needed.

0

stack and queue are referred as abstract datatype because in stack there are, mainly two operations push and pop and in queue there are insertion and deletion. Which are when operated on any set of data then it is free from that which type of data that must be contained by the set. For example when we convert from infix (i,e, a+b) to postfix expression (i.e, ab+) then it the set may be contain parenthesis or set of digits or set of characters or combination of three. so that's why stack and queue are referred as abstract data type .

Bhaskara Arani
  • 1,556
  • 1
  • 26
  • 44