
Array Structure and Operations in C Programming
Explore array structure in C programming, including creation, display, updating, copying, joining, concatenation, reversing, insertion, deletion, searching, sorting, and merging. Learn about array declaration, initialization, creation algorithm, and display algorithm. Practice replacing data in an array and displaying in reverse order, with practical examples and code snippets.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
Department of Master of Computer Applications St. Joseph s College (Autonomous) Tiruchirappalli - 2 Semester Semester III ARRAY STRUCTURE Programme Programme M Sc/ MCA Course Code Course Code 18SCS3101A Course Course DESIGN AND ANALYSIS OF ALGORITHMS Prof. V. S. Joe Irudayaraj Associate Professor of Computer Science
ARRAY STRUCTURE What is an Array? Group of elements are represented in a single name called an Array. Array is a set of pairs, index and value. Array has consecutive memory locations. Array is a random access structure. Array is a homogeneous structure, that is it consists same type of data.
g Operations onArray 1. Creation 2. Display 3. Updating 4. Copying 5. Joining 6. Concatenation 7. Reversing 8. Insertion 9. Deletion 10. Searching 11. Sorting 12. Merging
g DECLARATION IN C int a[10], char c[5], char * name[10]; INITIALIZATION IN C 1. int a[ ] = {10,20,30,40,50}; 2. char c[ ] = { A , B , C }; 2. char * name = { RAJA , RANI };
g CREATE AN ARRAY OF n ELEMENTS ALGORITHM: 1. read n 2. for i= 1 to n do read a[i] C PROGRAM: 1. scanf( %d ,&n); 2. for(i=1;i<=n;++i) scanf( %d ,&a[i] );
g DISPLAY AN ARRAY OF n ELEMENTS ALGORITHM: for i= 1 to n do write a[i] C PROGRAM: for(i=1;i<=n;++i) printf( %d ,a[i] );
g Give number of elements 4 Give data one by one 10 20 30 40 Given Data 10 20 30 40
g DISPLAY AN ARRAY IN REVERSE ORDER ALGORITHM: for i= n downto 1 do write a[i] C PROGRAM: for(i=n;i>=1;--i) printf( %d ,a[i] );
g Give number of elements 4 Give data one by one 10 20 30 40 Given Data in reverse order 40 30 20 10
g REPLACE DATA x AT LOCATION j WHERE 1<=j<=n (GIVEN : ARRAY OF N ELEMENTS) 1. read x,j 2. a[j]=x
g Given Array 10 20 30 40 Give new data to replace 80 Give position 3 New Array 10 20 80 40
g COPY ARRAY A OF m elements TO ARRAY B 1. for i= 1 to m do b[i] = a[i]
g JOIN ARRAY B OF n elements TO ARRAY A of m elements 1. for j= 1 to n do a[m+j] = b[j] 2. m = m+n;
g REVERSE AN ARRAY OF n ELEMENTS 1. for i= 1 to n/2 do a[i] a[n-i+1]
g CREATE and DISPLAY AN ARRAY OF n ELEMENTS ALGORITHM: 1. read n 2. for i= 1 to n do read a[i] 3. for i= 1 to n do write a[i]
g Give number of elements 4 Give data one by one 10 20 30 40 Given Array 10 20 30 40
g REVERSE AN ARRAY OF n ELEMENTS 1. for i= 1 to n/2 do a[i] a[n-i+1]
g Given Array 10 20 30 40 Reversed Array 40 30 20 10
g INSERT DATA x AT LOCATION j WHERE 1<=j<=n (GIVEN : ARRAY OF n ELEMENTS) 1. read x 2. read j 3. for i = n downto j do a[i+1] = a[i] 4. a[j] = x 5. n = n+1
g Given Array 10 20 30 40 Give new data to insert 100 Give its position 2 New Array after insertion 10 100 20 30 40
g Given Array 10 20 30 40 Give new data to insert 100 Give its position 1 New Array after insertion 100 10 20 30 40
g Given Array 10 20 30 40 Give new data to insert 100 Give its position 5 New Array after insertion 10 20 30 40 100
g INSERT DATA x AT THE END OF AN ARRAY (GIVEN : ARRAY OF n ELEMENTS) 1. read x 2. a[ n + 1] = x 3. n = n+1
g Given Array 10 20 30 40 Give new data to insert at rear 100 New Array after insertion 10 20 30 40 100
g DELETE DATA AT LOCATION j WHERE 1<=j<=n (GIVEN : ARRAY OF n ELEMENTS) 1. read j 2. for i = j+1 to n do a[i-1] = a[i] 3. n = n-1
g Given Array 10 20 30 40 Give data to delete 30 New Array after deletion 10 20 40
g Given Array 10 20 30 40 Give data to delete 40 New Array after deletion 10 20 30
g Given Array 10 20 30 40 Give data to delete 10 New Array after deletion 20 30 40
g DELETE DATA x FROM AN ARRAY OF n ELEMENTS 1. read x 2. for i = 1 to n do if (a[i]=x) break 3. if (i=n+1) then {write( Not Found ); return;} else { for j= i+1 to n do a[j-1] = a[j] n=n-1 }
g MERGE TWO SORTED ARRAYS ARRAY A OF m ELEMENTS WITH ARRAY B OF n ELEMENTS 1. i=1; j=1 2. a[m+1] = ; a[n+1]= 3. for k= 1 to m+n do { if (a[i] <= b[j]) then {c[k]=a[i]; i=i+1} else {c[k]=b[j]; j=j+1} }
MATRIX: MAGIC SQUARE (4i, i = 1, 2, 3, ) 16 2* 3* 13 5* 11 10 8* 9* 7 6 12* 4 14* 15* 1 n (n2+1) Sum = -------------- 2 Try for Singly Even Magic Square (4i+2, i =1, 2, 3, )
ODD MAGIC SQUARE (2i, i = 1, 2, 3, ) 8 1 6 3 5 7 4 9 2