Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

1.

Abstract Data Type (ADT) –


Abstract Data type (ADT) is a type (or class) for objects whose behavior is defined by a set of
values and a set of operations. The definition of ADT only mentions what operations are to be
performed but not how these operations will be implemented. It does not specify how data will
be organized in memory and what algorithms will be used for implementing the operations. It
is called “abstract” because it gives an implementation-independent view.
The process of providing only the essentials and hiding the details is known as abstraction.
The user of does not need to know how that data type is implemented, for example, we have
been using Primitive values like int, float, char data types only with the knowledge that these data type
can operate and be performed on without any idea of how they are implemented.
So a user only needs to know what a data type can do, but not how it will be implemented.

Features of ADT:
 Abstraction: The user does not need to know the implementation of the data structure only
essentials are provided.
 Better Conceptualization: ADT gives us a better conceptualization of the real world.
 Robust: The program is robust and has the ability to catch errors .

LIST ADT –

The data is generally stored in key sequence in a list

Node contains two field data which is actual data value and next field is address of next node

Functions of List ADT -

i) isEmpty() – Return true if the list is empty, otherwise return false.


ii) isFull() – Return true if the list is full, otherwise return false.
iii) get() – Return an element from the list at any given position.
iv) insert() – Insert an element at any position of the list.

Stack ADT –

In Stack ADT Implementation instead of data being stored in each node, the pointer to data is
stored.
stack head also contains a pointer to top and count of number of entries currently in stack.

Functions in Stack ADT –

i) isEmpty() – Return true if the stack is empty, otherwise return false.


ii) isFull() – Return true if the stack is full, otherwise return false.
iii) push() – Insert an element at one end of the stack called top.
iv) pop() – Remove and return the element at the top of the stack, if it is not empty.

Queue ADT –
Queue ADT follows the basic design of the stack abstract data type.
Each node contains data and the link pointer to the next element in the queue then responsibility is to
allocate memory for storing the data.
Functions of Queue ADT –
i) isEmpty() – Return true if the queue is empty, otherwise return false.
ii) isFull() – Return true if the queue is full, otherwise return false.
iii) enqueue() – Insert an element at the end of the queue.
iv) dequeue() – Remove and return the first element of the queue, if the queue is not empty.

2. Array –
Array is collection of elements of same data types

e.g. – int a[11];

here 11 elements of int type data

Declaration of array –

Data-type array-name [size];

Example –

int arr[11];

o Index starts with 0.

o The array's length is 11, which means we can store 11 elements.

o Each element in the array can be accessed via its index.

Basic operations –

o Traversal - This operation is used to print the elements of the array.


o Insertion - It is used to add an element at a particular index.
o Deletion - It is used to delete an element from a particular index.
o Search - It is used to search an element using the given index or by
the value.
o Update - It updates an element at a particular index.
i) Traversal Operation –

#include <stdio.h>

void main() {

int Arr[5] = {1,2,3,4,5};

int i;

printf("Elements of the array \n");

for(i = 0; i<5; i++)


{

printf("Arr[%d] = %d, ", i, Arr[i]);

ii) Insertion Operation –

#include <stdio.h>

void main()

int arr[20] = { 1,2,3,4,5 };

int i, x, pos, n = 5;
printf("Array elements before insertion\n");

for (i = 0; i < n; i++)

printf("%d ", arr[i]);

x = 50; // element to be inserted

pos = 4;

n++;

for (i = n-1; i >= pos; i--)

arr[i] = arr[i - 1];


arr[pos - 1] = x;

printf("Array elements after insertion\n");


for (i = 0; i < n; i++)

printf("%d ", arr[i]);

printf("\n");

getch();

iii) Deletion Operation –

#include <stdio.h>

void main()

int arr[] = {1,2,3,4,5};

int k = 2, n = 5;

int i, j;

printf(" array elements are :\n");


for(i = 0; i<n; i++) {

printf("arr[%d] = %d, ", i, arr[i]);

j = k;
while( j < n) {

arr[j-1] = arr[j];

j = j + 1;

n = n -1;

printf("Elements of array after deletion\n");

for(i = 0; i<n; i++)

{
printf("arr[%d] = %d, ", i, arr[i]);

}
}

iv) Search Operation –

#include <stdio.h>

void main()

int arr[5] = {1,2,3,4,5};

int ele = 4, i, j=0 ;

printf(" array elements are :\n");

for(i = 0; i<5; i++)

{
printf("arr[%d] = %d, ", i, arr[i]);

printf(" Searched Element = %d", ele);

while( j < 5){


if( arr[j] == ele )

break;

}
j = j + 1;

}
printf("\Element %d is found at %d position", ele, j+1);

}
v) Update Operation -

#include <stdio.h>

void main()

int arr[5] = {1,2,3,4,5};

int ele = 7, i, pos = 3;

printf("Array elements are \n");


for(i = 0; i<5; i++)

printf("arr[%d] = %d, ", i, arr[i]);

}
arr[pos-1] = ele;

printf("Array elements after updation :\n");

for(i = 0; i<5; i++)

{
printf("arr[%d] = %d, ", i, arr[i]);

Types of Array –

One -Dimensional Arrays -


A one-dimensional array is a linear array. It involves single sub-scripting. The [] (brackets) is used for
the subscript of the array and to declare and access the elements from the array.
Syntax: DataType ArrayName [size];
For example: int a[10];

Multi-Dimensional Arrays -
In multi-dimensional arrays, we have two categories:
 Two-Dimensional Arrays
 Three-Dimensional Arrays

1. Two-Dimensional Arrays –

An array involving two subscripts [] [] is known as a two-dimensional array.


They are also known as the array of the array.
Syntax: DataType ArrayName[row_size][column_size];
For Example: int arr[5][5];

2. Three-Dimensional Arrays –

When we require to create two or more tables of the elements to declare the array elements, then in such a
situation we use three-dimensional arrays.
Syntax: DataType ArrayName[size1][size2][size3];
For Example: int a[5][5][5];

3. Array as ADT –
The array is a basic ADT that holds an ordered collection of items accessible by an integer index
Arrays are defined as ADT’s because they are capable of holding contiguous elements in the
same order. And they permit access for the specific element via index or position.
Example –
They are abstract because they can be int , String
int[] arr = new int[1];

String[] arr1 = new String[1];


The array is an abstract data type (ADT) that holds a collection of elements accessible by an index.
The Array (ADT) have one property, they store and retrieve elements using an index. The array
(ADT) is usually implemented by an Array (Data Structure).
Array Elements

1 2 3 4 5 6 7 9

Array Index

You might also like