SlideShare a Scribd company logo
Array
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
Array
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

More Related Content

What's hot (20)

PPTX
Frequency count of the Element in an array
Kavya Shree
 
PDF
Java & OOP Core Concept
Pin-Lun Huang
 
PPT
Hight Work
Nutron
 
PDF
HyperLogLog in Hive - How to count sheep efficiently?
bzamecnik
 
PDF
Big Data Day LA 2015 - Large Scale Distinct Count -- The HyperLogLog algorith...
Data Con LA
 
PDF
Functional Programming with JavaScript
Mark Shelton
 
PPT
Python 101 language features and functional programming
Lukasz Dynowski
 
PDF
Core Java Programming Language (JSE) : Chapter V - Arrays
WebStackAcademy
 
PDF
Brief intro to clojure
Roy Rutto
 
PPTX
Data Type C# - Lec2 (Workshop on C# Programming: Learn to Build)
Jannat Ruma
 
PDF
FIWARE Real-time Processing of Historic Context Information using Apache Flin...
sonsoleslp
 
PPTX
C# Basic - Lec1 (Workshop on C# Programming: Learn to Build)
Jannat Ruma
 
PPTX
Type Casting C# - Lec4 (Workshop on C# Programming: Learn to Build)
Jannat Ruma
 
PDF
뱅크샐러드 파이썬맛 레시피
겨울 정
 
PPTX
Synapse india dotnet development overloading operater part 4
Synapseindiappsdevelopment
 
ODP
Visualising your garbage collection for Node.js
stalleyj
 
PPTX
Jug Marche: Meeting June 2014. Java 8 hands on
Onofrio Panzarino
 
PPTX
Simseer.com - Malware Similarity and Clustering Made Easy
Silvio Cesare
 
PPTX
Design and analysis of algorithm
laibaNoor60
 
PPT
Analysis of Algorithms-Heapsort
Reetesh Gupta
 
Frequency count of the Element in an array
Kavya Shree
 
Java & OOP Core Concept
Pin-Lun Huang
 
Hight Work
Nutron
 
HyperLogLog in Hive - How to count sheep efficiently?
bzamecnik
 
Big Data Day LA 2015 - Large Scale Distinct Count -- The HyperLogLog algorith...
Data Con LA
 
Functional Programming with JavaScript
Mark Shelton
 
Python 101 language features and functional programming
Lukasz Dynowski
 
Core Java Programming Language (JSE) : Chapter V - Arrays
WebStackAcademy
 
Brief intro to clojure
Roy Rutto
 
Data Type C# - Lec2 (Workshop on C# Programming: Learn to Build)
Jannat Ruma
 
FIWARE Real-time Processing of Historic Context Information using Apache Flin...
sonsoleslp
 
C# Basic - Lec1 (Workshop on C# Programming: Learn to Build)
Jannat Ruma
 
Type Casting C# - Lec4 (Workshop on C# Programming: Learn to Build)
Jannat Ruma
 
뱅크샐러드 파이썬맛 레시피
겨울 정
 
Synapse india dotnet development overloading operater part 4
Synapseindiappsdevelopment
 
Visualising your garbage collection for Node.js
stalleyj
 
Jug Marche: Meeting June 2014. Java 8 hands on
Onofrio Panzarino
 
Simseer.com - Malware Similarity and Clustering Made Easy
Silvio Cesare
 
Design and analysis of algorithm
laibaNoor60
 
Analysis of Algorithms-Heapsort
Reetesh Gupta
 

Viewers also liked (16)

PPT
Array
Mayank Saxena
 
PDF
Flash cars1
Weenndii
 
PDF
Photography
Villy Spectrum
 
PPTX
Treatement of abused children ppt lecture 2
Wesam Ayyad
 
PPT
Glosario (1)
raquelrogar
 
PPTX
Treatement of abused children ppt lecture 1
Wesam Ayyad
 
PPTX
Debbuging
Iama Marsian
 
PPTX
Pertemuan 1 konsep dasar sistem pakar
edi_suhardi
 
PPTX
Cryptography
Iama Marsian
 
PPTX
Chapter7
Wesam Ayyad
 
PPTX
History of Pain Theories
Hannah Kae
 
PPTX
Pci
Iama Marsian
 
PPTX
8085 microprocessor
Iama Marsian
 
PPTX
Effects of climate change on transport and their adaptation measures
Ranga Sameera
 
PPTX
Estudio crash 2
Rob Lucet
 
PPTX
Hemorragia gastrointestinal
Rob Lucet
 
Flash cars1
Weenndii
 
Photography
Villy Spectrum
 
Treatement of abused children ppt lecture 2
Wesam Ayyad
 
Glosario (1)
raquelrogar
 
Treatement of abused children ppt lecture 1
Wesam Ayyad
 
Debbuging
Iama Marsian
 
Pertemuan 1 konsep dasar sistem pakar
edi_suhardi
 
Cryptography
Iama Marsian
 
Chapter7
Wesam Ayyad
 
History of Pain Theories
Hannah Kae
 
8085 microprocessor
Iama Marsian
 
Effects of climate change on transport and their adaptation measures
Ranga Sameera
 
Estudio crash 2
Rob Lucet
 
Hemorragia gastrointestinal
Rob Lucet
 
Ad

Similar to Array (20)

PPTX
9.Sorting & Searching
Mandeep Singh
 
PPT
Array operations
Razzaaa
 
PDF
Quick sort,bubble sort,heap sort and merge sort
abhinavkumar77723
 
PPTX
Coin Changing, Binary Search , Linear Search - Algorithm
Md Sadequl Islam
 
DOCX
Updated Lab3.docx
AleezaAnjum
 
PPT
Array 2
Abbott
 
PPT
ds 2-Arrays and its types and operations
kavita20193
 
PPTX
Revisiting a data structures in detail with linked list stack and queue
ssuser7319f8
 
PPTX
Data structure and algorithm All in One
jehan1987
 
PPTX
Understanding Queue in Python using list 2019.pptx
Vinod Srivastava
 
PPTX
searching in data structure.pptx
chouguleamruta24
 
PPT
Data structure lecture7
Kumar
 
PPTX
introduction to data structures and types
ankita946617
 
PPTX
Stack and queue power point presentation data structure and algorithms Stack-...
abhaysingh19149
 
PPTX
Array Operations.pptxdata structure array indsa
ar0454492
 
PPT
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
Malikireddy Bramhananda Reddy
 
PDF
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
Sowmya Jyothi
 
PPT
Algorithm
sultanarun
 
PPTX
Lecture 02: Preliminaries of Data structure
Nurjahan Nipa
 
PPTX
Sorting techniques
JayeshGadhave1
 
9.Sorting & Searching
Mandeep Singh
 
Array operations
Razzaaa
 
Quick sort,bubble sort,heap sort and merge sort
abhinavkumar77723
 
Coin Changing, Binary Search , Linear Search - Algorithm
Md Sadequl Islam
 
Updated Lab3.docx
AleezaAnjum
 
Array 2
Abbott
 
ds 2-Arrays and its types and operations
kavita20193
 
Revisiting a data structures in detail with linked list stack and queue
ssuser7319f8
 
Data structure and algorithm All in One
jehan1987
 
Understanding Queue in Python using list 2019.pptx
Vinod Srivastava
 
searching in data structure.pptx
chouguleamruta24
 
Data structure lecture7
Kumar
 
introduction to data structures and types
ankita946617
 
Stack and queue power point presentation data structure and algorithms Stack-...
abhaysingh19149
 
Array Operations.pptxdata structure array indsa
ar0454492
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
Malikireddy Bramhananda Reddy
 
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
Sowmya Jyothi
 
Algorithm
sultanarun
 
Lecture 02: Preliminaries of Data structure
Nurjahan Nipa
 
Sorting techniques
JayeshGadhave1
 
Ad

Array