Aditya DSPM
Aditya DSPM
B.H.S.B.I.E.T
DSPM FILE
MANISH
2
ARRAY
MANISH
3
ALGORITHM:
Here LA is a linear array with lower bound LB and upper bound UB. This
algorithm traverses LA applying in operation PROCESS to each element of LA.
5. Exit.
MANISH
4
PROGRAM
#include<iostream.h>
#include<conio.h>
void main()
{
int a[10],n,i;
cout<<"ENETR NO. OF ARRAY ELEMENT "<<endl;
cin>>n;
cout<<"ENETR ARRAY ELEMENT "<<endl;
for(i=1;i<=n;i++)
{
cin>>a[i];
}
cout<<"ARRAY ELEMENT AFTER TRAVERSING ";
for(i=1;i<=n;i++)
{
cout<<a[i]<<endl;
}
getch();
}
MANISH
5
MANISH
6
ALGORITHM
INSERT (LA,N,K,ITEM)
Here LA is a linear array with N elements and K is a positive integer such that
K=N.This algorithm inserts an element ITEM into the Kth Position in LA
7 Exit
MANISH
7
PROGRAM
#include<iostream.h>
#include<conio.h>
void main()
{
int a[10],n,g,i,item;
cout<<”ENTER NO. OF ARRAY ELEMENT ";
cin>>n;
for(i=1;i<=n;i++)
{
cin>>a[i];
}
cout<<"ENTER THE POSITION WHERE ELEMENT TO BE INSERTED ";
cin>>g;
cout<<"ENTER THE ELEMENT TO BE INSERTED ";
cin>>item;
for(i=n;i>=g;i--)
{
a[i+1]=a[i];
}
a[g]=item;
for(i=1;i<=n+1;i++)
{
MANISH
8
cout<<a[i]<<endl;
}
getch();
}
MANISH
9
ALGORITHM
DELETE (LA ,N ,K ,ITEM)
Here LA is a linear array with N element and K is a positive integer such that
K<=N.
[End of loop]
4. Exit
MANISH
10
PROGRAM
#include<iostream.h>
#include<conio.h>
main()
int a[5],i,j,n,g;
for(i=1;i<=5;i++)
cin>>a[i];
cin>>g;
for(i=g;i<=5;i++)
a[i]=a[i+1];
n=n-1;
g=g-1;
MANISH
11
for(i=1;i<=4;i++)
cout<<a[i]<<" ";
getch();
MANISH
12
LINEAR SEARCH
Linear search is method to find the element in a linear array which is sorted or
unsorted. This search is useful in limited strength order.
ALGORITHM
LINEAR (DATA,N,ITEM,LOC)
Here DATA is a linear array with N element , and ITEM is a given item of
information .This algorithm finds the the location LOC of ITEM in DATA ,or set
LOC=0,if search is unsuccessful.
Set LOC=LOC+1;
5. Exit
MANISH
13
PROGRAM
#include<iostream.h>
#include<conio.h>
void main()
int a[10],n,g,i,item,flag=0;
cin>>n;
for(i=1;i<=n;i++)
cin>>a[i];
cin>>item;
for(i=1;i<=n;i++)
if(item==a[i])
MANISH
14
flag=1;
break;
if(flag==0)
getch();
MANISH
15
BINARY SEARCH
Binary search is used to search the element in a sorted list.As name tells it divides
the series in two half and reduce time complexity.
ALGORITHM
Here data is a sorted array with lower bound lb and upper bound UB and item is a
given item of information. The variables BEG , END and MID denote
,respectively, the beginning ,END middle location of a segment of elements of
data. This algorithm finds the location LOC of ITEM in DATA or sets
LOC=NULL.
Else:
Set BEG=MID+1.
[End of if structure]
MANISH
16
Set LOC=MID
Else:
Set LOC=NULL.
[End of if structure]
6. EXIT
MANISH
17
PROGRAM
#include<iostream.h>
#include<conio.h>
void main()
int a[10],n,g,i,item,flag=0,beg=1,mid,end;
cin>>n;
for(i=1;i<=n;i++)
cin>>a[i];
cin>>item;
end=n;
do
mid=(beg+end)/2;
if(item==a[mid])
flag=1;
MANISH
18
break;
else if(item<a[mid])
end=mid-1;
else
beg=mid+1;
while(beg<=end);
if(flag==0)
getch();
MANISH
19
MANISH
20
BUBBLE SORT
This method is used to sort the series in ascending or decending order.In this
elements are compare with each other and swap them if order does not fit to it.
ALGORITHM
BUBBLE(DATA,N)
(a) if DATA[PTR]>DATA[PTR+1],then:
Interchange DATA[PTR]andDATA[PTR+1].
[End of if structure.]
4.Exit.
PROGRAM
MANISH
21
#include<iostream.h>
#include<conio.h>
main()
int a[10],i,j,temp,n;
cin>>n;
for(i=1;i<=n;i++)
cin>>a[i];
for(i=1;i<n;i++)
for(j=1;j<=n;j++)
if(a[j]>a[j+1])
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
} }
MANISH
22
for(i=1;i<=n;i++)
cout<<a[i];
cout<<endl;
getch();
MANISH
23
MANISH