Data Structure BASIC Notes
Data Structure BASIC Notes
Data:- Data refers to a value or set of values. These values represent some observations from an
experiment, some figures collected during some surveys such as census exit polls etc or marks obtained
by students in examinations.
Information:- Information is a processed data. Data is just a collection of values(raw data) from which
no conclusion can be drawn. Data is not useful for decision making but information is useful for decision
making.
Data type:- A data type is a collection of values and a set of operations that act on those values so the
two aspects are important when we define data type:-
i) Set of values
ii) A set of operations
We may consider a basic data type- integer, on which mathematical as well as logical operations
are allowed. On integer data type addition, subtraction, multiplication, division and remainder division
is possible. But on float data type remainder division is not possible.
Primitive data type:- Primitive data type is a data type that is predefined in a language. The primitive
data type is also known as built-in data type. C language has three built in data types known as integer,
real and character.
Abstract data type:- An abstract data type (ADT) is a mathematical model for data types where a data
type is defined by its behavior from the point of view of a user of the data, specifically in terms of
possible values, possible operations on data of this type, and the behavior of these operations. Formally,
an ADT may be defined as a "class of objects whose logical behavior is defined by a set of values and a
set of operations".
Data structure:- An organised collection of data is called data structure. It involves the set of operations
possible on that particular data structure. So it can be said that:-
Data Structure = Organised data + Set of allowed operations
In other words, Data Structure is a logical model of a particular organisation of data. Data structures
are used in almost every program or software system. Some common examples of data structures are
arrays, linked lists, queues, stacks, trees and graph. Data structures are widely applied in the following
areas:
Compiler design
Operating system design
Statistical analysis package
DBMS
Numerical analysis
Simulation
Artificial intelligence
Graphics
2) Types of elements:- As far as types of elements of a data structure is concerned it can be categorised
in two types:-
i) Homogeneous data structure:- It is a structure in which elements/data are of same type. An
array is a homogeneous data structure.
ii) Non-homogeneous data structure:- In non-homogeneous data structure elements are not of
the same type. Records are common example of non-homogeneous data structure.
3) Memory allocation:- As far as memory allocation of a data structure is concerned it can be classified
into two categories:-
i) Static data structure:- It can’t expand or shrink during execution of the program. Its
associated memory location are fixed at compile time.
ii) Dynamic data structure:- These are one which can expand or shrink as required during the
execution of the program. The associated memory location of a dynamic data structure can
change if it is reallocated.
Array
Array:- An array is a collection of elements described by a single name. Elements of an array is
referenced by a subscript value also called index value. The index value is used within pair of brackets
after the name of array variable to refer an element of the array. Arrays are categorised into two types
depending on the number of subscript used with array name, they are
i) One dimensional or linear array
ii) Multidimensional array
i) One dimensional or Linear array:- One dimensional or linear array is list of finite number
N homogeneous data elements such that
a) The elements of the array referenced by an index set consisting of N consecutive integer
numbers.
b) The elements of the array is stored in consecutive memory locations.
Operations on array
i) Creation.
ii) Traversal:- a) in order
b) reverse order
iii) Insertion:-
a) at beginning
b) at end
c) at given position
d) after given element
e) before given element
f) in sorted array
iv) Deletion:-
a. from beginning
b. from end
c. from given position
d. of given element 1) from all occurrences 2) from first occurrence/once
e. after given element
f. before given element
g. duplicate elements
v) Searching:-
a. Sequential Search
b. Advanced Sequential Search
c. Binary Search:- 1) Iterative 2) Recursive
vi) Sorting:-
a. Bubble Sort and Modified Bubble Sort
b. Selection Sort
c. Insertion Sort
d. Quick Sort
e. Merge Sort
f. Heap Sort
vii) Merging/ Concatenation:-
a. Merging
b. Concatenation
Q. Write a program to create an array of 10 elements and display their elements in in-order and reverse
order.
#include<stdio.h>
#include<conio.h>
#define MAX 10
void create(int *,int *);
void display(int *,int );
void disp_rev(int *,int );
void main()
{
int a[MAX],n=0;
create(a,&n);
display(a,n);
disp_rev(a,n);
getch();
}
void create(int *a,int *n)
{
int ele;
printf("Enter the element(-1 to exit):");
while(1)
{
scanf("%d",&ele);
if(ele==-1)
break;
else
{
if(*n==MAX)
{
printf("Sorry…… Array is full.");
break;
}
else
a[(*n++)]=ele;
}
}
}
void display(int *a,int n)
{
int i;
if(n==0)
printf("Array is empty::");
else
{
printf("Elements of an array are:\n");
printf("\n Position Element");
for(i=0;i<n;i++)
printf("\n a[%d]=\t\t%d",i,a[i]);
}
}