In: Computer Science
Abstraction is a key part of object-oriented programming and the concepts apply particularly well to classes. How would the same concepts apply to data structures and how we tend to define and think of ADTs?
Abstraction:-
Show/provide necessary functions to the user and hiding the
internal implementation of the functions.
There are 2 kinds of abstraction in programming languages:-
1) Procedural abstraction
2) Data abstraction.
1) procedural abstraction :- It is a mental model of what we want a subprogram to do (but not how to do it).
2) Data abstraction:-
A data abstraction is a mental model of what should be done to
the collection of data.
We implement the data abstraction by 2 steps:-
2.1) choosing an appropriate data structure - a specific
construction of data
2.2) providing appropriate operations (algorithms) to manipulate
that data
Implementation of ADT:-
Implementing an ADT means providing a procedure or function for
each abstract operation.
Example:- An abstract stack data type can be implemented by the
linked list or by an array.
difference between ADT and data structure:-
ADT (Abstract Data Type) is of a logical description, while a Data
Structure is concrete.
Examples of data structures:-
Arrays,Stacks,Queues,Linked Lists,Trees,Graphs,Tries,Hash
Tables.
Abstract Data type (ADT) is a type (or class)
for objects whose behaviour is defined by the set of values and the
set of operations.
ADT gives an implementation-independent view.
The process of providing only the essentials and hiding the
internal details(implementation) is known as abstraction.
We can think of ADT as a black box because it shows the external
operation but doesn´t show the internal structure.
Examples of ADT:-
1) Container
2) List
3) Set
4) Multiset
5) Map
6) Multimap
7) Graph
8) Tree
9) Stack
10) Queue
11) Priority queue
12) Double-ended queue
13) Double-ended priority queue
Lets take some of the abstract data types and explain in this
way:-
1) List ADT
2) Stack ADT
3) Queue ADT
1) List ADT:-
List contains elements of the same type arranged in sequential
order.
operations in list:-
1) get() :- Return an element from the list in any given
position.
2) insert() :- Insert an element at any position of the list.
3) remove() :- Remove the first occurrence of any element from a
non-empty list.
4) removeAt() :- Remove the element at a specified location from a
non-empty list.
5) replace() :- Replace an element at any position by another
element.
6) size() :- Return the number of elements in the list.
7) isEmpty() :- Return true if the list is empty, otherwise return
false.
8) isFull() :- Return true if the list is full, otherwise return
false.
2) Stack ADT:-
A Stack contains elements of the same type arranged in sequential
order.It follows LIFO (last in first out) order.
operations:-
1) Push()
2) pop()
3)Peek()
4) Size()
5)isEmpty()
6) isFull()
3) Queue ADT:-
It contains elements of the same type that are arranged in the
sequential order.
Operations take place at both ends, insertion is done at the end
and deletion is done at the front in the queue.
operations:-
1) enqueue()
2) dequeue()
3) peek()
4) size()
5) isEmpty()
6) isFull()
Advantages of abstract data typing:-
1) Encapsulation
2) No editing of code object that uses ADT
3) Flexibility
We use the abstraction concept in object-oriented programming and as well as to classes.We can use the abstraction concept in data structures also.Because lets take an example
In stack data type: some operations to be shown to the user such as push,pop,peek,isempty,isnull.The programmer write the internal code of that functions and don´t need to show the user.Only the user is used the functions of the stack.In this way,we can use abstraction in the data structures.