Chapter 1
Chapter 1
Data structure can be defined as the collection of elements and all the possible operations which are
required for those set of elements. In other words data structure will tell us which are the elements
required as well as the legal operations on those set of elements
Data type
A data type is a term which refers to the kinds of data that variables may hold in the programming
language.
For example in “C”, the data types are int float, char, double etc.
Generally a programming language supports a set of built in data types and allows the user to define a
new type those are called user defined data types. So there are two types of data types:-
Built in data type: such as int, float, char, double which are defined by programming language itself
User defined data type- using the set of built in data types user can define his/her own data type.
Example:
typedef struct student{
int roll;
char name;
} s;
s s1;
s is tag for user defined data type which defines the structure student and s1 is variable of data
types.
Abstract data type (ADT)
An abstract data type (ADT) is the way we look at a data structure, focusing on what it
does and ignoring how it does its job.
An abstract data type (ADT) is a logical description of how we view the data and the
operations that are allowed on it. ADT is defined as a user point of view of a data type.
ADT concerns about the possible values of the data and what are interface exposed by it.
ADT does not concern about the actual implementation of the data structure.
For example, a user wants to store some integers and find a mean of it. Does not talk
about how exactly it will be implemented.
Stack ADT Operations
Push(k): Adds a new item to the top of the stack
Pop(): Remove an element from the top of the stack and return its value.
Top(): Returns the value of the element at the top of the stack
Size(): Returns the number of elements in the stack
IsEmpty(): determines whether the stack is empty. It returns 1 if the stack is empty or return 0.
Note: All the above Stack operations are implemented in O(1) Time Complexity.