Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

Data Structure BASIC Notes

The document provides an overview of data structures, defining key concepts such as data, information, data types, and the distinction between primitive and abstract data types. It categorizes data structures based on physical representation, types of elements, and memory allocation, while also detailing common operations like creation, traversal, searching, and sorting. Additionally, it includes specific implementations and functions for handling arrays in C programming, demonstrating operations such as insertion, deletion, and display.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Data Structure BASIC Notes

The document provides an overview of data structures, defining key concepts such as data, information, data types, and the distinction between primitive and abstract data types. It categorizes data structures based on physical representation, types of elements, and memory allocation, while also detailing common operations like creation, traversal, searching, and sorting. Additionally, it includes specific implementations and functions for handling arrays in C programming, demonstrating operations such as insertion, deletion, and display.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Data Structure

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

Types of data structure:- Data Structure can be categorized on the basis of


1) Physical representation:- As far as physical representation of a data structure is concerned it may
be categorised into two types:-
i) Linear data structure:- Elements of a linear data structure forms a sequence. Ex- Arrays, linked
list, stack, queue etc.
ii) Non-linear data structure:- The structure whose elements do not form a sequence is called
non-linear data structure. Tree, graph are examples of non-linear data structures.

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.

Common operations on data structure:-


i) Creation- Creation means initialising a data structure and inserting elements /nodes at beginning and
provide it to user for other operations.
ii) Traversal:- Accessing each element/ nodes exactly once in order to process it is called traversal. This
operation is also known as visiting the nodes/elements.
iii) Searching:- Finding the location of a given element in a data structure is called searching.
iv) Insertion:- Adding a new element/node to the data structure is called insertion.
v) Deletion:- Removing an element/node from a data structure is called deletion.
vi) Sorting:- Arranging elements in some logical order is called sorting. This logical order may be
ascending or descending order in case of numeric data type. In case of alphabet it may be in dictionary
order.
vii) Merging/Concatenation:- Combining elements of two similar data structure is called merging or
concatenation.

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]);
}
}

void disp(int *a,int n)


{
int i;
clrscr();
if(n==0)
printf("list is empty");
else
{
printf("Elements of array are:");
printf("Position Element \n");
for(i=0;i<n;i++)
printf("\n a[%d]=\t%d",i,a[i]);
}
}
void disp_rev(int *a,int n)
{
int i;
clrscr();
if(n==0)
printf("List is empty");
else
{
printf("Elements of array in reverse order are:");
printf("Position Element \n");
for(i=n-1;i>0;i--)
printf("\n a[%d]=\t%d",i,a[i]);
}
}

Q. Function to insert an element at beginning of an array.


Prototype:- void insbeg(int *, int *);
Call:- insbeg(a,&n);
Definition:-
void insbeg(int *a,int*n)
{
int i,ele;
clrscr();
if(*n==MAX)
printf("Array is full. Insertion not possible");
else
{
printf("Enter element to be inserted at beg:");
scanf("%d",&ele);
for(i=*n;i>0;i--)
a[i]=a[i-1];
a[0]=ele;
(*n)++;
}
}

Q. Function to insert an element at end of an array.


Prototype:- void insend(int *, int *);
Call:- insend(a,&n);
Definition:-
void insend(int *a,int *n)
{
int i,ele;
clrscr();
if(*n==MAX)
printf("Array is full. Insertion not possible");
else
{
printf("Enter element to be inserted at beg:");
scanf("%d",&ele);
a[*n]=ele;
(*n)++;
}
}

Q. Function to insert an element at given position in an array.


Prototype:- void inspos(int *, int *)
Call:- inspos(a,&n);
Definition:-
void inspos(int *a,int *n)
{
int i,ele,pos;
clrscr();
if(*n==MAX)
printf("Array is full. Insertion not possible");
else
{
printf("Enter position where you want to insert:");
scanf("%d",&pos);
if(pos<0||pos>*n)
printf("Invalid position value. Insertion not possible");
else
{
printf("Enter element to be inserted:");
scanf("%d",&ele);
for(i=*n;i>pos;i--)
a[i]=a[i-1];
a[pos]=ele;
(*n)++;
}
}
}

Q. Function to insert an element after given element in an array.


Prototype:- void insaft(int *,int *);
Call:- insaft(a,&n);
Definition:-
void insaft(int *a,int *n)
{
int ele,i,pos;
clrscr();
if(*n==MAX)
printf("List is full. Insertion not possible");
else
{
printf("Enter element after which you want to insert:");
scanf("%d",&ele);
for(pos=0;pos<*n;pos++)
if(a[pos]==ele)
break;
if(pos==*n)
printf("Element not found");
else
{
printf("Enter element to be inserted:");
scanf("%d",&ele);
for(i=*n;i>pos+1;i--)
a[i]=a[i-1];
a[i]=ele;
(*n)++;
}
}
}

Q. Function to insert an element before given element in an array.


Prototype:- void insbef(int *, int *);
Call:- insbef(a,&n);
Definition:-
void insbef(int *a,int *n)
{
int ele,i,pos;
clrscr();
if(*n==MAX)
printf("List is full. Insertion not possible");
else
{
printf("Enter element before which you want to insert:");
scanf("%d",&ele);
for(pos=0;pos<*n;pos++)
if(a[pos]==ele)
break;
if(pos==*n)
printf("Element not found");
else
{
printf("Enter element to be inserted:");
scanf("%d",&ele);
for(i=*n;i>pos;i--)
a[i]=a[i-1];
a[i]=ele;
(*n)++;
}
}
}

Q. Function to insert an element in a sorted array.


Prototype:- void inssorted(int *, int *);
Call:- inssorted(a,&n);
Definition:-
void inssorted(int *a,int *n)
{
int ele,i;
clrscr();
if(*n==MAX)
printf("List is full. Insertion not possible.");
else
{
printf("Enter element to be inserted:");
scanf("%d",&ele);
for(i=*n;i>0;i--)
if(a[i-1]>ele)
a[i]=a[i-1];
else
break;
a[i]=ele;
(*n)++;
}
}

You might also like