DEFINATION:- 
• An array is a list of finite number of 
homogeneous data elements (i.e. data 
elements of the same type). 
• They are referenced by an index set. 
• They are stored respectively in 
successive memory locations.
VARIOUS OPERATIONS:- 
• Traversal 
• Search 
• Insertion 
• Deletion 
• Sorting 
• Merging
TRAVERSING:- 
Algorithm:- 
1. Set K:=LB 
2. Repeat Step 3 and 4 while K≤UB 
3. Apply process to LA[K] 
4. Set K=K+1 
5. EXIT
TRAVERSING:- 
Program:- 
#include<iostream.h> 
void main() 
{ 
int LA[5]={1,5,9,2,6}; 
int LB=0,UB=4; 
int K=LB;
while(K<=UB) 
{ 
cout<<LA[K]<<“ ”; 
} 
}
Output:-
INSERTION:- 
Algorithm:- 
INSERT(LA,N,K,ITEM) 
1. Set J:=N 
2. Repeat steps 3 and 4 while J ≥ K 
3. Set LA[J+1]:=LA[J] 
4. Set J:=J-1 
5. Set N=N+1 
6. Exit
Program:- 
#include<iostream.h> 
void main() 
{ 
int LA[6]={1,5,9,2,6}; 
int N=5, J=N, K, ITEM;
for(int i=0;i<N;i++) 
{ 
cout<<LA[i]<<“ ”; 
} 
cout<<“Enter the position: ”; 
cin>>K; 
cout<<“Enter the item: ”; 
cin<<ITEM;
while(J>=K) 
{ 
LA[J+1]=LA[J]; 
J=J-1; 
} 
LA[K]=ITEM; 
N=N+1; 
for(i=0;i<N;i++) 
{ 
cout<<LA[i]<<“ ”; 
} 
}
Output:-
DELETION:- 
Algorithm:- 
DELETE(LA,N,K,ITEM) 
1. Set ITEM=LA[K] 
2. Repeat for J=K to N-1 
Set LA[J]=LA[J+1] 
3. Set N=N-1 
4. Exit
Program:- 
#include<iostream.h> 
void main() 
{ 
int LA[6]={1,5,9,2,6}; 
int N=5, J, K=0, ITEM;
for(int i=0;i<N;i++) 
{ 
cout<<LA[i]<<“ ”; 
} 
cout<<“Enter the position: ”; 
cin>>K; 
ITEM=LA[K];
for(J=K; J<=N-1; J++) 
{ 
LA[J]=LA[J+1]; 
} 
N=N-1; 
for(i=0;i<N;i++) 
{ 
cout<<LA[i]<<“ ”; 
} 
}
Output:-
LINEAR SEARCH:- 
Algorithm:- 
LINEAR(LA,N,ITEM,LOC) 
1. Set LA[N+1]=ITEM 
2. SET LOC=1 
3. Repeat while LA[LOC] ≠ ITEM 
Set LOC=LOC+1 
4. If LOC=N+1, then set LOC=0 
5. Exit
Program:- 
#include<iostream.h> 
void main() 
{ 
int LA[7]={0,1,5,9,2,6}; 
int N=5, LOC=1, ITEM;
for(int i=1;i<=N;i++) 
{ 
cout<<LA[i]<<“ ”; 
} 
cout<<“Enter the item: ”; 
cin>>ITEM; 
LA[N+1]=ITEM;
while(LA[LOC] != ITEM) 
{ 
LOC=LOC+1; 
} 
if(LOC=N+1) 
{ 
LOC=0; 
} 
cout<<“Item found on Location: ” 
<<LOC; 
}
Output:-
BINARY SEARCH:- 
Algorithm:- 
BIANRY(DATA, LB, UB, ITEM, 
LOC) 
1. Set BEG=LB, END=UB and 
MID=(int)(BEG+END)/2 
2. Repeat steps 3 and 4 while 
BEG≤END and 
DATA[MID]≠ITEM 
3. If ITEM<DATA[MID], then 
set END=MID-1 
Else set BEG=MID+1 
4. Set MID=(int)(BEG+END)/2
5. If DATA[MID]=ITEM, then 
set LOC=MID 
Else set LOC=NULL 
6. Exit
Program:- 
#include<iostream.h> 
void main() 
{ 
int DATA[6]={0,11,22,33,44,55}; 
int LB=1, UB=5,ITEM 
BEG=LB,END=UB, 
MID=(BEG+END)/2;
for(int i=1;i<6;i++) 
{ 
cout<<DATA[i]<<“ ”; 
} 
cout<<“Enter the Item: ”; 
cin>>ITEM;
while(BEG<=END&& 
DATA[MID]!=ITEM) 
{ 
if(ITEM<DATA[MID]) 
{ END=MID-1; } 
else 
{ BEG=MID+1; } 
MID=(BEG+END)/2; 
}
if(DATA[MID]==ITEM) 
{ LOC=MID; } 
else 
{ LOC=0; } 
cout<<“Item found on Location: ” 
<<LOC; 
}
Output:-
BUBBLE SORT:- 
Algorithm:- 
BUBBLE(DATA,N) 
1. Repeat steps 2 and 3 for K=1 to N-1 
2. Set PTR=1 
3. Repeat while PTR≤N-K 
a. If DATA[PTR]>DATA[PTR+1] 
then interchange 
DATA[PTR] and DATA[PTR+1] 
b. Set PTR=PTR+1 
4. Exit
Program:- 
#include<iostream.h> 
void main() 
{ 
int DATA[10]={48,29,57,90,83,12, 
54,21,65,26}; 
int K, PTR; 
cout<<“Elements Before Sorting:-n”; 
for(K=0;K<10;K++) 
{ cout<<DATA[K]<<“ ”; }
for(K=1;K<10;K++) 
{ 
PTR=0; 
while(PTR<10-K) 
{ 
if(DATA[PTR]>DATA[PTR+1]) 
{ 
int TEMP=DATA[PTR]; 
DATA[PTR]=DATA[PTR+1]; 
DATA[PTR+1]=TEMP; 
} 
PTR=PTR+1; 
} 
}
cout<<“Elements After Sorting:- n”; 
for(K=0;K<10;K++) 
{ 
cout<<DATA[K]<<“ ”; 
} 
}
Output:-
THANKS

Array