Data Structure
Data Structure
STRUCTURES
-SWATHI R (BCA IST YEAR ‘A’)
ARRAY
OPERATIONS
Here is where my presentation begins
INTRODUCTION
● An array is a fundamental data structure that is
widely used in computer science and programming.
• Accessing elements
• Modifying elements
• Traversing elements
• Searching for a elements
• Merging two arrays
• Splitting an arrays
WHY DO WE NEED ARRAY OPERATIONS?
● Efficient storage and retrieval of data: Arrays provide a
convenient way to store a collection of elements of the same type in
contiguous memory locations. By using array operations, we can
efficiently access and manipulate the elements of an array.
● Data analysis: In many applications, we need to analyze and
manipulate large datasets. Arrays provide an efficient way to store
and access this data, and array operations allow us to process it in
various ways.
● Algorithm design: Many algorithms involve manipulating arrays.
For example, sorting algorithms, searching algorithms, and graph
algorithms often require array operations to work efficiently.
● Software development: Arrays are used extensively in software
development, from simple applications to complex systems. By
understanding array operations, developers can write more efficient
and effective code.
.
DEFINITION OF CONCEPTS
Here, size represents the memory taken by the primitive data types. As an instance, int takes 2
bytes, float takes 4 bytes of memory space in C programming.
• We can understand it with the help of an example -
Suppose an array, A[-10 ..... +2 ] having Base address (BA) = 999 and size of an element = 2 bytes, find
the location of A[-1].
L(A[-1]) = 999 + 2 x [(-1) - (-10)]
= 999 + 18
= 1017
BASIC OPERATIONS
Now, let's discuss the basic operations supported in the array –
Traversal - This operation is used to print the elements of the array.
Insertion - It is used to add an element at a particular index.
Deletion - It is used to delete an element from a particular index.
Search - It is used to search an element using the given index or by
the value.
Update - It updates an element at a particular index
ADVANTAGES OF ARRAY
int arr[max_rows][max_columns];
EXAMPLE PROGRAM
#include <stdio.h>
void main() {
int Arr[5] = {18, 30, 15, 70, 12};
int i;
printf("Elements of the array are:\n");
for(i = 0; i<5; i++) {
printf("Arr[%d] = %d, ", i, Arr[i]);
}
}
OUTPUT