SlideShare a Scribd company logo
SEMINAR  ON   ARRAYS UNDER THE GUIDENCE OF- Ms. PINKI MA’M PREPARED BY- SAURABH SHUKLA & SAURABH VYAS B.E. 2 nd  Yr.  1Vth Sem
11/01/11 ARRAYS INTRODUCTION  AND  CHARACTERISTICS AN ARRAY CAN BE DEFINED AS FINITE COLLECTION  OF HOMOGENOUS (SIMILAR TYPE) ELEMENTS  AN ARRAY CAN STORE EITHER ALL INTEGERS,ALL FLOATING  POINT NUMBERS,ALL CHARACTERS  etc.  ARRAYS ARE ALWAYS STORED IN CONSECUTIVE MEMORY  LOCATIONS IT CAN BE INITIALIZED EITHER DURING  DECLARATION TIME   OR DURING RUN TIME   TYPES ONE DIMENSIONAL ARRAY  TWO DIMENSIONAL ARRAY  .  .  MULTI DIMENSIONAL ARRAY
11/01/11 DECLARATION OF ONE DIMENSIONAL ARRAY Data_type var_name[Expression] Data Type  is the type of elements to be stored in the array Var_name  is the name of the array like any  Other variables  Expression  specifies the number of elements to be stored  In array Example  int num[10];   Num[0] =data1 Num[1] =data2 Num[2] =data3 Num[3] =data4 Num[4] =data5 Num[5] =data6 Num[6] =data7 Num[7] =data8 Num[8] =data9 Num[9] =data10
11/01/11 ACCESSING ONE DIMENSIONAL ARRAY ELEMENTS #<Include<stdio.h> #include<conio.h> Void main()  {  Int a[10];  Clrscr();  Printf (“enter the array”); For (i=0;i<10;i++)  {  Scanf(“%d”,&a[i]); }   Printf(“the entered array is”); For(i=0;i<10;i++)  {  printf(“%d”,a[i]);} }   getch();  }   Arrray  declaration  Taking values from user Printing the values OUTPUT Enter the array 1 2 3 4 5 6 7 8 9 10 Entered array is 1 2 3 4 5 6 7 8 9 10
11/01/11 OPERATIONS  IN  ARRAY INSERTION  DELETION  MERGING TWO ARRAYS  TRAVERSING  SORTING  SEARCHING
11/01/11 ALGORITHM 1 . [INITIALIZE THE VALUE OF i] SET i =len  2 . REPEAT FOR i=len DOWN TO pos  {SHIFT ELEMENTS DOWN BY 1 POSITION}  SET a[i+1]=a[i]  [END OF LOOP]  3 . [INSERT THE ELEMENT AT REQUIRED POSITION] SET a[pos]=num 4 . [RESET len] SET len =len +1  5 . DISPLAY THE NEW LIST OF ARRAYS  6. END  INSERTION
11/01/11 INSERTION Int i,len,pos,num; Void main() {  int a[10]; Void insert (int a[ ],int,int,int); Printf(“enter integers to be read”); Scanf(“%d”,&len); Printf(:enter ur array”); For(i=0;1<len;i++) { scanf(“%d”,&a[i]); } Printf(:enter position”); Scanf(“%d”,&pos); --pos; Printf(:enter integer to be inserted”); Scanf(“%d”,&num); Insert(a,len,pos,num);} For(i=len;1pos;i--) {a[i+1])=a[i]; } A{pos]=num; Len ++; Printf(“new array is ”); For(i=0;i<len;i++) { printf(“%d”,&a[i]); }   } ORIGINAL ARRAY 1  2  3  4  5  6  7  8 HOW IT WORKS ENTER POSITION   4 ENTER NUM   9 DURING PROCESSING 1  2  3  ……..  4  5  6  7  8 NEW ARRAY 1  2  3  …9….  4  5  6  7  8 THE  ACTUAL 4 th  POSITION
11/01/11 ALGORITHM 1. SET item=a[pos]  2. REPEAT FOR i=pos to (n-1)  [SHIFTING ELEMENTS 1 POSITION DOWNWARDS ] SET a[i]=a[i+1]  [END OF LOOP]  3. RESET n=n-1  4. DISPLAY ELEMENTS OF NEW ARRAY  5. END  DELETION
11/01/11 DELETION Int i,n; Void main() {   Int a[10],pos; Void delete(int a[ ],int,int); Printf(“enter no of elements in array”); Scanf(“%d”,&n); Printf(“enter ur array”); For(i=0;i<n;i++) Scanf(“%d”,&a[i]); Printf(:enter position”); Scanf(“%d”,&pos); --pos; delete(a[ ],pos,n);  Void delete(int a [ ],int pos,int n) {  int j item; Item =a[pos]; For(j=pos;j<n;j++) a[j]=a[j+1]; n=n-1;  } For(i=0;i<n;i++) printf(“%d”,&a[i]);  } HOW IT WORKS ORIGINAL ARRAY 1  2  3  4  5  6  7  8 ENTER POSITION   4 DURING PROCESSING 1  2  3  4  5  6  7  8 NEW ARRAY 1  2  3  5  6  7  8 THE  ACTUAL 4 th  POSITION
11/01/11 ALGORITHM Letr LB be the lower bound andUB be the  upper bound of linear array a 1. [initialize the counter]  Set I at lower bound LB  2. Repeat for i=LB to UB  [visit element]Display element a[i] [end of the loop] 3. EXIT  TRAVERSING
11/01/11 TRAVERSING AN ARRAY #include<stdio.h> Void main ( ) { Int i,n,a[10]; printf)(“enter length of the array”); Scanf(“%d”,&n); Printf(“enter ur array”); For(i=0;i<n;i++) Scanf(“%d”,&a [ i ]); Printf(“traversing the array”); For(i=0;i<n;i++) printf(“%d”,&a [ i ]); } OUTPUT 1 2 3 4 5 TRAVERSING THE ARRAY ENTER UR ARRAY 1  2  3  4  5  ENTER LENGTH OF ARRAY  5
11/01/11 MERGING OF THE TWO ARRAYS MERGING MEANS COMBINING ELEMENTS OF TWO ARRAYS TO FORM A NEW ARRAY  THIS CAN  BE DONE IN 2 WAYS---- 1.  FIRST COPY ALL ELEMENTS OF ARRAY 1 TO ARRAY3  THEN ARRAY2 TO ARRAY3  THEN SORT  THE RESULTANT ARRAY3  2.  SECOND WAY IS TO SORT THE ARRAY DURING MERGING. THIS TECHNIQUE IS CALLED SORTING WHILE MERGING  AND IT IS MORE EFFICIENT ONE
11/01/11 void main() { int a[10],b[10],c[10],i,j,k=0,l,m,n; cout<<&quot;Enter sizeof array1 and array2” ;    cin>>m>>n;    cout<<&quot;Enter elements of 1st:\n&quot;;  for(i=0;i<m;i++) {cin>>a[i];}  cout<<&quot;Elements of 2nd list:\n&quot;;  for(i=0;i<n;i++)  {cin>>b[i];}   for(i=0;i<m;i++)  {c[i]=a[i];}  for(j=0;j<n;j++)  {c[j+m]=b[j];}  for(i=0;i<(m+n);i++) {for(j=0;j<(m+n);j++) {if(c[i]<c[j]) {k=c[j];  c[j]=c[i]; c[i]=k; }}} cout<<&quot;New merged array :&quot;; for(i=0;i<(m+n);i++) {cout<<c[i]<<&quot;\t&quot;;} } PROGRAM OUTPUT Enter size of array1 and array2  5 6 Enter elements of 1 st: 5 9 16 50 80 Elements of 2 nd  list: 11 32 49 58 75 98 New merged array : 5 9 11 16 32 49 50 58 75 80 98
11/01/11 ALGORITHM SEARCHING [ Insert item at the end of data ] set  data[n+1]=item. [ Initialize counter ] set loc = 1. [ Search for item ] Repeat while data[loc] =! Item Set loc = loc +1. [ Successful ] if loc=n+1 , then set loc = 0. Exit
11/01/11 SEARCHING Int i,n; Void main() {   Int a[10],pos=-1,k; Printf(“enter no of elements in array”); Scanf(“%d”,&n); Printf(“enter ur array”); For(i=0;i<n;i++) Scanf(“%d”,&a[i]); Printf(:enter no. to be searched :”); Scanf(“%d”,&k);   For(j=0;j<n;j++) {if (k==a[j]) {pos=i; break;}  } If (pos>=0) printf(“\n%d is found in position %d”,k,pos+1); Else printf(“\nelement does not exist”); getch();  } OUTPUT Enter no of elements in array: 6 Enter ur array: 10 20 30 40 50 60 Enter no to be searched : 50 50 is found in position 5 OUTPUT Enter no of elements in array: 6 Enter ur array: 10 20 30 40 50 60 Enter no to be searched : 45 Element does not exist
11/01/11 SORTING SORTING REFERS TO THE OPERATION OFARRANGING DATA IN  SOME GIVEN SEQUENCE ie.  ASCENDING OR DESCENDING ORDER . SORTING IS OF 2 TYPES---- 1. INTERNAL SORTING —MEANS ARRANGING THE NOs. WITHIN  THE ARRAY ONLY WHICH IS IN CXOMPUTER PRIMARY  MEMORY.   2. EXTERNAL SORTING ----IT IS THE SORTING OF NOs. FROM  EXTERNAL FILE  BY RADING IT FROM SECONFDARY  MEMORY.   TYPES 1.BUBBLE SORT  2.SELECTION SORT 3.INSERTION SORT  4.QUICK SORT  5.MEARGE SORT  etc.
11/01/11 SELECTION   SORTINNG THIS TECHNIQUE IS BASED UPON THE EXTENSION  OF MINIMUM / MAXIMUM TECHNIQUE.  BY MEANS OF NESTED FOR LOOPS ,MINIMUM VALUE IS FOUND OUT.  ONCE THIS IS FOUND ,IT IS PLACED IN 1 st  POSITION  OF   ARRAY  ie. Position 0  THEN WE’LL FIND THE NEXT SMALLEST  ELEMENT  FROM REMAINING ELEMENTS  AND NOW THIS ELEMENT IS PLACED IN 2 nd  POSITION ie. Position 1
11/01/11 PROGRAM #include<stdio.h> void main() { int a[10],i,n,j,x; printf(&quot;enter the value of n  \n&quot;); scanf(&quot;%d&quot;,&n); printf(&quot;enter array  \n&quot;); for(i=0;i<n;i++) { scanf(&quot;%d&quot;,&a[i]);} printf(&quot; ur  unsorted array is  \n&quot;); for(i=0;i<n;i++) { printf(&quot;%d  &quot;,a[i]);} for(i=0;i<n;i++) {  for(j=0;j<n;j++) {  if(a[j]>a[i]) {  x=a[i]; a[i]=a[j]; a[j]=x;  }  } } printf(&quot; ur sorted  array  is \n&quot;); for(j=0;j<n;j++) {printf(&quot;%d  &quot;,a[j]);} } SELECTION SORTING
11/01/11 interchange 16 13 15 EXAMPLE ENTERED ARRAY a[0] a[1] a[2] a[3] a[4] 6 PASS 1 13 16 6 2 15 PASS 2 13 16 15 2 6 PASS 3  16 13 15 2 6 PASS 4 15 13 16 2 6 PASS 5 13 2 6 16 15 2
11/01/11 BUBBLE SORTING IN BUBBLE SORT, EACH ELEMENT IS COMPARED  WITH ITS ADJECENT  ELEMENT.IF 1 st  ELEMENT IS LARGER THAN THE 2 nd  ONE THE  POSITION GETS INTERCHANGED,OTHERWISE NOT.  AND NEXTELEMENT IS COMPARED WITH ITS ADJECENT ELEMENT AND SAME PROCESS IS REPEATED  EXAMPLE INITIAL ELEMENTS (without sorting) 11  15  2  13  6
11/01/11 EXAMPLE > 11 13 ENTERED ARRAY a[0] a[1] a[2] a[3] a[4] 6 PASS 1 6 13 15 11 2 PASS 2 13 6 15 2 11 PASS 3  11 13 15 2 6 PASS 4 13 11 15 2 6 RESULT 13 2 6 11 15 2 < > > > < > < < > < < < < < < 15
11/01/11 LIMITATIONS OF  LINEAR ARRAYS THE PRIOR KNOWLEDGE OF NO. OF ELEMENTS IN THE LINEAR ARRAY IS NECESSARY THESE ARE STATIC STRUCTURES STATIC IN THE SENSE THAT MEMORY IS ALLOCATED AT COMPILATION TIME, THEIR MEMORY USED BY THEM CAN’T BE REDUCED  OR EXTENDED SINCE THE ELEMENTS OF THIS ARRAYS ARE STORED IN THESE ARRAYS ARE TIME CONSUMING THIS IS B’COZ OF MOVING DOWN OR UP TO CREATE A SPACE OF NEW ELEMENT  OR TO OCCUPY THE SPACE  VACATED BY DELETED ELEMENT
11/01/11 FROM  SAURABH SHUKLA  &  SAURABH  VYAS

More Related Content

What's hot (20)

PDF
Array linear data_structure_2 (1)
eShikshak
 
PPTX
Arrays in Data Structure and Algorithm
KristinaBorooah
 
PPT
standard template library(STL) in C++
•sreejith •sree
 
PPTX
Java presentation on insertion sort
_fahad_shaikh
 
PPT
Unit 1 introduction to data structure
kalyanineve
 
PPT
Queue
Nabeel Ahsen
 
PPTX
Programming in c Arrays
janani thirupathi
 
PPT
Arrays
archikabhatia
 
PPTX
Abstract Data Types
karthikeyanC40
 
PPTX
Priority Queue in Data Structure
Meghaj Mallick
 
PPTX
Counting Sort
Faiza Saleem
 
PPT
Repetition Structure
PRN USM
 
PDF
Expression trees
Salman Vadsarya
 
PPT
Data Structure and Algorithms
ManishPrajapati78
 
PPTX
Computer Science-Data Structures :Abstract DataType (ADT)
St Mary's College,Thrissur,Kerala
 
PPTX
Quick sort-Data Structure
Jeanie Arnoco
 
PPTX
Introduction to Array ppt
sandhya yadav
 
PPTX
queue & its applications
somendra kumar
 
PPT
Queue Data Structure
Lovely Professional University
 
PPTX
heap Sort Algorithm
Lemia Algmri
 
Array linear data_structure_2 (1)
eShikshak
 
Arrays in Data Structure and Algorithm
KristinaBorooah
 
standard template library(STL) in C++
•sreejith •sree
 
Java presentation on insertion sort
_fahad_shaikh
 
Unit 1 introduction to data structure
kalyanineve
 
Programming in c Arrays
janani thirupathi
 
Abstract Data Types
karthikeyanC40
 
Priority Queue in Data Structure
Meghaj Mallick
 
Counting Sort
Faiza Saleem
 
Repetition Structure
PRN USM
 
Expression trees
Salman Vadsarya
 
Data Structure and Algorithms
ManishPrajapati78
 
Computer Science-Data Structures :Abstract DataType (ADT)
St Mary's College,Thrissur,Kerala
 
Quick sort-Data Structure
Jeanie Arnoco
 
Introduction to Array ppt
sandhya yadav
 
queue & its applications
somendra kumar
 
Queue Data Structure
Lovely Professional University
 
heap Sort Algorithm
Lemia Algmri
 

Viewers also liked (7)

PPTX
Array in C
Kamal Acharya
 
PPT
Dbs3024 biz trx week 2 double entry system
Stephen Ong
 
PPSX
C Programming : Arrays
Gagan Deep
 
PPTX
Double entry system
RaJesh Thakur
 
PPT
Double entry systme
Asian Institute of Virtual Learning
 
PPT
Double Entry
creativemedia
 
PPTX
Array in c language
home
 
Array in C
Kamal Acharya
 
Dbs3024 biz trx week 2 double entry system
Stephen Ong
 
C Programming : Arrays
Gagan Deep
 
Double entry system
RaJesh Thakur
 
Double Entry
creativemedia
 
Array in c language
home
 
Ad

Similar to Array Presentation (EngineerBaBu.com) (20)

PPT
Arrays
SARITHA REDDY
 
PPT
Unit6 C
arnold 7490
 
PPT
computer notes - Data Structures - 38
ecomputernotes
 
PDF
CP PPT_Unit IV computer programming in c.pdf
saneshgamerz
 
PPT
Array 31.8.2020 updated
vrgokila
 
PPT
Chapter 10.ppt
MithuBose3
 
PDF
Data structures arrays
maamir farooq
 
PPT
358 33 powerpoint-slides_5-arrays_chapter-5
sumitbardhan
 
PDF
Array data structure
harsh112327
 
PPTX
Various Operations Of Array(Data Structure Algorithm).pptx
atirathpal007
 
PDF
Array data structure
maamir farooq
 
PPT
Computer notes - Sorting
ecomputernotes
 
PPTX
Arrays in C.pptx
HarsimranKaur362773
 
PPTX
CSE 1102 - Lecture 6 - Arrays in C .pptx
Salim Shadman Ankur
 
PDF
Working of Merge Sort Code
Muhammad Abdullah
 
DOC
A sorted linear array
Suneel Dogra
 
PPTX
Ds chapter 2
Prof .Pragati Khade
 
PDF
Unit 4
SHIKHA GAUTAM
 
DOCX
One dimensional operation of Array in C- language
9096308941
 
Unit6 C
arnold 7490
 
computer notes - Data Structures - 38
ecomputernotes
 
CP PPT_Unit IV computer programming in c.pdf
saneshgamerz
 
Array 31.8.2020 updated
vrgokila
 
Chapter 10.ppt
MithuBose3
 
Data structures arrays
maamir farooq
 
358 33 powerpoint-slides_5-arrays_chapter-5
sumitbardhan
 
Array data structure
harsh112327
 
Various Operations Of Array(Data Structure Algorithm).pptx
atirathpal007
 
Array data structure
maamir farooq
 
Computer notes - Sorting
ecomputernotes
 
Arrays in C.pptx
HarsimranKaur362773
 
CSE 1102 - Lecture 6 - Arrays in C .pptx
Salim Shadman Ankur
 
Working of Merge Sort Code
Muhammad Abdullah
 
A sorted linear array
Suneel Dogra
 
Ds chapter 2
Prof .Pragati Khade
 
One dimensional operation of Array in C- language
9096308941
 
Ad

Recently uploaded (20)

PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
PDF
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
PDF
People & Earth's Ecosystem -Lesson 2: People & Population
marvinnbustamante1
 
PDF
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PDF
community health nursing question paper 2.pdf
Prince kumar
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PDF
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
How to Set Maximum Difference Odoo 18 POS
Celine George
 
PPTX
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
People & Earth's Ecosystem -Lesson 2: People & Population
marvinnbustamante1
 
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
community health nursing question paper 2.pdf
Prince kumar
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
How to Set Maximum Difference Odoo 18 POS
Celine George
 
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
Dimensions of Societal Planning in Commonism
StefanMz
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 

Array Presentation (EngineerBaBu.com)

  • 1. SEMINAR ON ARRAYS UNDER THE GUIDENCE OF- Ms. PINKI MA’M PREPARED BY- SAURABH SHUKLA & SAURABH VYAS B.E. 2 nd Yr. 1Vth Sem
  • 2. 11/01/11 ARRAYS INTRODUCTION AND CHARACTERISTICS AN ARRAY CAN BE DEFINED AS FINITE COLLECTION OF HOMOGENOUS (SIMILAR TYPE) ELEMENTS AN ARRAY CAN STORE EITHER ALL INTEGERS,ALL FLOATING POINT NUMBERS,ALL CHARACTERS etc. ARRAYS ARE ALWAYS STORED IN CONSECUTIVE MEMORY LOCATIONS IT CAN BE INITIALIZED EITHER DURING DECLARATION TIME OR DURING RUN TIME TYPES ONE DIMENSIONAL ARRAY TWO DIMENSIONAL ARRAY . . MULTI DIMENSIONAL ARRAY
  • 3. 11/01/11 DECLARATION OF ONE DIMENSIONAL ARRAY Data_type var_name[Expression] Data Type is the type of elements to be stored in the array Var_name is the name of the array like any Other variables Expression specifies the number of elements to be stored In array Example int num[10]; Num[0] =data1 Num[1] =data2 Num[2] =data3 Num[3] =data4 Num[4] =data5 Num[5] =data6 Num[6] =data7 Num[7] =data8 Num[8] =data9 Num[9] =data10
  • 4. 11/01/11 ACCESSING ONE DIMENSIONAL ARRAY ELEMENTS #<Include<stdio.h> #include<conio.h> Void main() { Int a[10]; Clrscr(); Printf (“enter the array”); For (i=0;i<10;i++) { Scanf(“%d”,&a[i]); } Printf(“the entered array is”); For(i=0;i<10;i++) { printf(“%d”,a[i]);} } getch(); } Arrray declaration Taking values from user Printing the values OUTPUT Enter the array 1 2 3 4 5 6 7 8 9 10 Entered array is 1 2 3 4 5 6 7 8 9 10
  • 5. 11/01/11 OPERATIONS IN ARRAY INSERTION DELETION MERGING TWO ARRAYS TRAVERSING SORTING SEARCHING
  • 6. 11/01/11 ALGORITHM 1 . [INITIALIZE THE VALUE OF i] SET i =len 2 . REPEAT FOR i=len DOWN TO pos {SHIFT ELEMENTS DOWN BY 1 POSITION} SET a[i+1]=a[i] [END OF LOOP] 3 . [INSERT THE ELEMENT AT REQUIRED POSITION] SET a[pos]=num 4 . [RESET len] SET len =len +1 5 . DISPLAY THE NEW LIST OF ARRAYS 6. END INSERTION
  • 7. 11/01/11 INSERTION Int i,len,pos,num; Void main() { int a[10]; Void insert (int a[ ],int,int,int); Printf(“enter integers to be read”); Scanf(“%d”,&len); Printf(:enter ur array”); For(i=0;1<len;i++) { scanf(“%d”,&a[i]); } Printf(:enter position”); Scanf(“%d”,&pos); --pos; Printf(:enter integer to be inserted”); Scanf(“%d”,&num); Insert(a,len,pos,num);} For(i=len;1pos;i--) {a[i+1])=a[i]; } A{pos]=num; Len ++; Printf(“new array is ”); For(i=0;i<len;i++) { printf(“%d”,&a[i]); } } ORIGINAL ARRAY 1 2 3 4 5 6 7 8 HOW IT WORKS ENTER POSITION 4 ENTER NUM 9 DURING PROCESSING 1 2 3 …….. 4 5 6 7 8 NEW ARRAY 1 2 3 …9…. 4 5 6 7 8 THE ACTUAL 4 th POSITION
  • 8. 11/01/11 ALGORITHM 1. SET item=a[pos] 2. REPEAT FOR i=pos to (n-1) [SHIFTING ELEMENTS 1 POSITION DOWNWARDS ] SET a[i]=a[i+1] [END OF LOOP] 3. RESET n=n-1 4. DISPLAY ELEMENTS OF NEW ARRAY 5. END DELETION
  • 9. 11/01/11 DELETION Int i,n; Void main() { Int a[10],pos; Void delete(int a[ ],int,int); Printf(“enter no of elements in array”); Scanf(“%d”,&n); Printf(“enter ur array”); For(i=0;i<n;i++) Scanf(“%d”,&a[i]); Printf(:enter position”); Scanf(“%d”,&pos); --pos; delete(a[ ],pos,n); Void delete(int a [ ],int pos,int n) { int j item; Item =a[pos]; For(j=pos;j<n;j++) a[j]=a[j+1]; n=n-1; } For(i=0;i<n;i++) printf(“%d”,&a[i]); } HOW IT WORKS ORIGINAL ARRAY 1 2 3 4 5 6 7 8 ENTER POSITION 4 DURING PROCESSING 1 2 3 4 5 6 7 8 NEW ARRAY 1 2 3 5 6 7 8 THE ACTUAL 4 th POSITION
  • 10. 11/01/11 ALGORITHM Letr LB be the lower bound andUB be the upper bound of linear array a 1. [initialize the counter] Set I at lower bound LB 2. Repeat for i=LB to UB [visit element]Display element a[i] [end of the loop] 3. EXIT TRAVERSING
  • 11. 11/01/11 TRAVERSING AN ARRAY #include<stdio.h> Void main ( ) { Int i,n,a[10]; printf)(“enter length of the array”); Scanf(“%d”,&n); Printf(“enter ur array”); For(i=0;i<n;i++) Scanf(“%d”,&a [ i ]); Printf(“traversing the array”); For(i=0;i<n;i++) printf(“%d”,&a [ i ]); } OUTPUT 1 2 3 4 5 TRAVERSING THE ARRAY ENTER UR ARRAY 1 2 3 4 5 ENTER LENGTH OF ARRAY 5
  • 12. 11/01/11 MERGING OF THE TWO ARRAYS MERGING MEANS COMBINING ELEMENTS OF TWO ARRAYS TO FORM A NEW ARRAY THIS CAN BE DONE IN 2 WAYS---- 1. FIRST COPY ALL ELEMENTS OF ARRAY 1 TO ARRAY3 THEN ARRAY2 TO ARRAY3 THEN SORT THE RESULTANT ARRAY3 2. SECOND WAY IS TO SORT THE ARRAY DURING MERGING. THIS TECHNIQUE IS CALLED SORTING WHILE MERGING AND IT IS MORE EFFICIENT ONE
  • 13. 11/01/11 void main() { int a[10],b[10],c[10],i,j,k=0,l,m,n; cout<<&quot;Enter sizeof array1 and array2” ; cin>>m>>n; cout<<&quot;Enter elements of 1st:\n&quot;; for(i=0;i<m;i++) {cin>>a[i];} cout<<&quot;Elements of 2nd list:\n&quot;; for(i=0;i<n;i++) {cin>>b[i];} for(i=0;i<m;i++) {c[i]=a[i];} for(j=0;j<n;j++) {c[j+m]=b[j];} for(i=0;i<(m+n);i++) {for(j=0;j<(m+n);j++) {if(c[i]<c[j]) {k=c[j]; c[j]=c[i]; c[i]=k; }}} cout<<&quot;New merged array :&quot;; for(i=0;i<(m+n);i++) {cout<<c[i]<<&quot;\t&quot;;} } PROGRAM OUTPUT Enter size of array1 and array2 5 6 Enter elements of 1 st: 5 9 16 50 80 Elements of 2 nd list: 11 32 49 58 75 98 New merged array : 5 9 11 16 32 49 50 58 75 80 98
  • 14. 11/01/11 ALGORITHM SEARCHING [ Insert item at the end of data ] set data[n+1]=item. [ Initialize counter ] set loc = 1. [ Search for item ] Repeat while data[loc] =! Item Set loc = loc +1. [ Successful ] if loc=n+1 , then set loc = 0. Exit
  • 15. 11/01/11 SEARCHING Int i,n; Void main() { Int a[10],pos=-1,k; Printf(“enter no of elements in array”); Scanf(“%d”,&n); Printf(“enter ur array”); For(i=0;i<n;i++) Scanf(“%d”,&a[i]); Printf(:enter no. to be searched :”); Scanf(“%d”,&k); For(j=0;j<n;j++) {if (k==a[j]) {pos=i; break;} } If (pos>=0) printf(“\n%d is found in position %d”,k,pos+1); Else printf(“\nelement does not exist”); getch(); } OUTPUT Enter no of elements in array: 6 Enter ur array: 10 20 30 40 50 60 Enter no to be searched : 50 50 is found in position 5 OUTPUT Enter no of elements in array: 6 Enter ur array: 10 20 30 40 50 60 Enter no to be searched : 45 Element does not exist
  • 16. 11/01/11 SORTING SORTING REFERS TO THE OPERATION OFARRANGING DATA IN SOME GIVEN SEQUENCE ie. ASCENDING OR DESCENDING ORDER . SORTING IS OF 2 TYPES---- 1. INTERNAL SORTING —MEANS ARRANGING THE NOs. WITHIN THE ARRAY ONLY WHICH IS IN CXOMPUTER PRIMARY MEMORY. 2. EXTERNAL SORTING ----IT IS THE SORTING OF NOs. FROM EXTERNAL FILE BY RADING IT FROM SECONFDARY MEMORY. TYPES 1.BUBBLE SORT 2.SELECTION SORT 3.INSERTION SORT 4.QUICK SORT 5.MEARGE SORT etc.
  • 17. 11/01/11 SELECTION SORTINNG THIS TECHNIQUE IS BASED UPON THE EXTENSION OF MINIMUM / MAXIMUM TECHNIQUE. BY MEANS OF NESTED FOR LOOPS ,MINIMUM VALUE IS FOUND OUT. ONCE THIS IS FOUND ,IT IS PLACED IN 1 st POSITION OF ARRAY ie. Position 0 THEN WE’LL FIND THE NEXT SMALLEST ELEMENT FROM REMAINING ELEMENTS AND NOW THIS ELEMENT IS PLACED IN 2 nd POSITION ie. Position 1
  • 18. 11/01/11 PROGRAM #include<stdio.h> void main() { int a[10],i,n,j,x; printf(&quot;enter the value of n \n&quot;); scanf(&quot;%d&quot;,&n); printf(&quot;enter array \n&quot;); for(i=0;i<n;i++) { scanf(&quot;%d&quot;,&a[i]);} printf(&quot; ur unsorted array is \n&quot;); for(i=0;i<n;i++) { printf(&quot;%d &quot;,a[i]);} for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(a[j]>a[i]) { x=a[i]; a[i]=a[j]; a[j]=x; } } } printf(&quot; ur sorted array is \n&quot;); for(j=0;j<n;j++) {printf(&quot;%d &quot;,a[j]);} } SELECTION SORTING
  • 19. 11/01/11 interchange 16 13 15 EXAMPLE ENTERED ARRAY a[0] a[1] a[2] a[3] a[4] 6 PASS 1 13 16 6 2 15 PASS 2 13 16 15 2 6 PASS 3 16 13 15 2 6 PASS 4 15 13 16 2 6 PASS 5 13 2 6 16 15 2
  • 20. 11/01/11 BUBBLE SORTING IN BUBBLE SORT, EACH ELEMENT IS COMPARED WITH ITS ADJECENT ELEMENT.IF 1 st ELEMENT IS LARGER THAN THE 2 nd ONE THE POSITION GETS INTERCHANGED,OTHERWISE NOT. AND NEXTELEMENT IS COMPARED WITH ITS ADJECENT ELEMENT AND SAME PROCESS IS REPEATED EXAMPLE INITIAL ELEMENTS (without sorting) 11 15 2 13 6
  • 21. 11/01/11 EXAMPLE > 11 13 ENTERED ARRAY a[0] a[1] a[2] a[3] a[4] 6 PASS 1 6 13 15 11 2 PASS 2 13 6 15 2 11 PASS 3 11 13 15 2 6 PASS 4 13 11 15 2 6 RESULT 13 2 6 11 15 2 < > > > < > < < > < < < < < < 15
  • 22. 11/01/11 LIMITATIONS OF LINEAR ARRAYS THE PRIOR KNOWLEDGE OF NO. OF ELEMENTS IN THE LINEAR ARRAY IS NECESSARY THESE ARE STATIC STRUCTURES STATIC IN THE SENSE THAT MEMORY IS ALLOCATED AT COMPILATION TIME, THEIR MEMORY USED BY THEM CAN’T BE REDUCED OR EXTENDED SINCE THE ELEMENTS OF THIS ARRAYS ARE STORED IN THESE ARRAYS ARE TIME CONSUMING THIS IS B’COZ OF MOVING DOWN OR UP TO CREATE A SPACE OF NEW ELEMENT OR TO OCCUPY THE SPACE VACATED BY DELETED ELEMENT
  • 23. 11/01/11 FROM SAURABH SHUKLA & SAURABH VYAS