ARRAYS AND ABSTRACT DATA TYPE IN DATA STRUCTURE

 


Arrays and Abstract Data Type in Data Structure : 

These are data types created by the programmer to give the required functionalities to a user to perform certain required operations .Let’s understand deeper what is abstract data type.

Looking at the word abstract which means hidden. The word signifies that the user can only access the functions that the data type provides but will be unknown about how it’s made. Its similar to a driver who can access clutch staring accelerator etc. but is mostly unknown about the mechanism of the car when he uses the functions of the car.

In this course of Data structures and algorithms we will create abstract data types of data structures to store, and access data according to our requirement.
Taking example of an array:

If you are from a coding background or have learnt a programming language them you must have heard about arrays. For those who have not heard of it… let me elaborate.

Array is a data structure that allows to arrange and access data in linear fashion i.e., storing data in a line. We access data from an array using the index of the element.



This is an example of an array where indexes are starting from zero. 
The element at zeroth index is 8, 1st index is 6, 2nd index contains 9 and so on
The array has a size of 10 integers as there are only 10 elements in it.

The main problem with arrays is we cannot increase the size of an array. 
The array whose size cannot be changed is called a static array. 

If we want more elements in the array what we need to do is create a larger array copy the elements of previous array and add more elements ahead. This is a hectic task to solve this problem.

We can create Dynamic array - an array whose size can be changed using concept of  Abstract Data Type. But first 
We can create a data type of our own that will provide a function to add or remove elements in an array.

Abstract data type (ADT) of array
1. Basic Functions:-
 
get ( i ) – get element i
set ( i, num ) – set element i to num.

2. Operations:-

- Max()
- Min()
- Search ( num )
- Insert ( i, num )
- Append (x)

To achieve this what we need to do is dynamic memory allocation.

To understand about dynamic memory allocation we need to understand how our memory is structured.



In this memory structure the dynamic memory allocation takes place in the heap section if you want to learn more about the memory structure you can search it separately on google because explain it will make the post a lot longer
Coming back to our topic we can create ADT in various ways using different programming languages. Eg. We can use structures in C language, Classes in C++ and Java.
In the next post we will be taking a look at the algorithm to create ADT and will be coding in C language to create ADT.
 
NOTE: TO UNDERSTAND THE PROGRAMING PART, FROM THE NEXT POST WE WILL BE USING C LANGUAGE SO PLEASE MAKE SURE THAT YOU KNOW C LANGUAGE AND THE CONCEPT OF STRUCTURES IN C.

#KEEP LEARNING KEEP GROWING

Post a Comment

0 Comments