






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The basic operations that can be performed on arrays, including insertion, deletion, searching, display, traverse, and update. It provides detailed algorithms and code examples in c and c++ for each operation. The insertion operation involves adding an element to the array, either at the beginning, end, or a specific index. The deletion operation removes an element from a specific index by shifting the subsequent elements. The search operation uses sequential search to find an element in the array based on a given key. The traverse operation prints all the elements in the array, while the update operation modifies an existing element at a given index. The document serves as a comprehensive guide to understanding and implementing these fundamental array operations, which are essential for data manipulation and management in programming.
Typology: Study notes
1 / 11
This page cannot be seen from the preview
Don't miss anything!







Basic Operations in the Arrays The basic operations in the Arrays are insertion, deletion, searching, display, traverse, and update. These operations are usually performed to either modify the data in the array or to report the status of the array. Following are the basic operations supported by an array. Traverse − print all the array elements one by one. Insertion − Adds an element at the given index. Deletion − Deletes an element at the given index. Search − Searches an element using the given index or by the value. Update − Updates an element at the given index. Display − Displays the contents of the array.
1. Insertion Operation In the insertion operation, we are adding one or more elements to the array. Based on the requirement, a new element can be added at the beginning, end, or any given index of array. This is done using input statements of the programming languages. Array Insertion Algorithm Following is an algorithm to insert elements into a Linear Array until we reach the end of the array −
for(i = 0 ; i < 3 ; i++) { LA[i] = i + 2 ; printf("LA[%d] = %d \n", i, LA[i]); } return 0 ; } Output Array Before Insertion: LA[0] = 587297216 LA[1] = 32767 LA[2] = 0 Inserting Elements.. The array elements after insertion : LA[0] = 2 LA[1] = 3 LA[2] = 4 (ii) C++ Language #include
Output The original array elements are : LA[0] = 1 LA[1] = 3 LA[2] = 5 The array elements after deletion : LA[0] = 1 LA[1] = 5 (ii) C++ Language #include
3. Search Operation Searching an element in the array using a key; The key element sequentially compares every value in the array to check if the key is present in the array or not. Array Search Algorithm Consider LA is a linear array with N elements and K is a positive integer such that K<=N. Following is the algorithm to find an element with a value of ITEM using sequential search.
4. Traversal Operation This operation traverses through all the elements of an array. We use loop statements to carry this out. Algorithm Following is the algorithm to traverse through all the elements present in a Linear Array − 1 Start
(ii) C++ Language #include
5. Update Operation Update operation refers to updating an existing element from the array at a given index. Array Update Algorithm Consider LA is a linear array with N elements and K is a positive integer such that K<=N. Following is the algorithm to update an element available at the Kth position of LA.
cout << "LA[" << i << "] = " << LA[i] << endl; return 0 ; } Output The original array elements are : LA[0] = 1 LA[1] = 3 LA[2] = 5 LA[3] = 7 LA[4] = 8 The array elements after updation are : LA[0] = 1 LA[1] = 3 LA[2] = 10 LA[3] = 7 LA[4] = 8
6. Display Operation This operation displays all the elements in the entire array using a print statement. Array Display Algorithm
printf("LA[%d] = %d \n", i, LA[i]); } } Output The original array elements are : LA[0] = 1 LA[1] = 3 LA[2] = 5 LA[3] = 7 LA[4] = 8 (ii) C++ Language #include