Friday, February 18, 2022

Array II Part (Traverse, Insert, Delete Operation)

 

Arrays: Operations

Traversal, Insertion, Deletion

Pankaj Kumar Gupta

Head, BCA Department

Durga Prasad Baljeet Singh (PG) College, Anoopshahr

District Bulandshahr (Uttar Pradesh)

 



Abstract:

This Paper describes full discussion about  operations of Array Data Structures like: Traversal, Insertion, Deletion. Discussions about Algorithms and Procedures of same above defined operations also made in this paper.  

 

Keywords:

Array, Homogenous, Contiguous, Linear, Primary, Lower Bound, Upper Bound, SDA, Insert, Delete, Traverse.

 

Meaning of array:

Computer Application we define Array as: it is a Linear Data Structure. It is also termed as a collection of homogenous data elements. All the elements of an array share common name and stored on contiguous locations. It is also categorized into derived data types.

Example:

1.      A collection of roll numbers of 50 students (int).

2.      A collection of marks of 50 students in 6 subjects for a class (float).

3.      A collection of names of 50 students (char).

 

Categories of Arrays:

Arrays are categorized into 3 categories that are defined as follows:

1.      Single Dimensional Arrays.

2.      Two Dimensional Arrays.

3.      Multidimensional Arrays.

 

Operations of Array Data Structures:

Various operations are performed on Array Data Structure, that are as follows:

Here Discussion is made on Single Dimensional Array.

1.      Traversal

2.      Insertion

3.      Deletion

4.      Searching

5.      Sorting

6.      Merging

But Traverse, Insert & Delete operations are discussed in this paper.

 

Traversal:

Traversal is a process of visiting each and every node of a list in systematic manner. That means to go through each and every item of the list at least once.

Algorithm TRAVERSEARRAY(A,N,LB,UB)

/* Here TRAVERSEARRAY is an algorithm which is used to traverse all the elements of Array A with N elements. LB is Lower bound & UB is the Upper bound of Array. */

Step-1 Start

Step-2 set K=LB.

Step-3 Repeat steps 4 and 5 while K<=UB

Step-4 PROCESS A[K].

Step-5 set K=K+1.

Step-6 Exit.

 

Insertion:

Insertion is a process of adding one or more items in the given list. If an array of elements is given and an item is said to add at specific location. If array is already full then insertion operation results “Overflow”. To insert the item into array, all the elements from that location are shifted to the right side of the Array. Specific location may in:

1.      Beginning of the Array

2.      Middle anywhere

3.      Last of the Array

Here Lower bound is considered to be as 0.

Array A is given as A[5]={1,2,3,4}

 

           


Item to be inserted is 55

Location is:

At Beginning: New array will be like:

           


 

In Middle anywhere (Loc=2 as index): New array will be like:

           


 

 

At Last: New array will be like:

           


Algorithm INSERTARRAY(A,N,ITEM,LOC)

/* Here INSERTARRAY is an algorithm which is used to insert an ITEM on the Location LOC in an Array A with N elements. Lower bound of A is considered to be 0. */

Step-1 Start

Step-2 set J=N.

Step-3 Repeat steps 4 and 5 while K>=LOC

Step-4 set A[J]=A[J-1].

Step-5 set J=J-1.

Step-6 set A[LOC]:=ITEM.

Step-7 set N:=N+1.

Step-8 Exit.

Deletion:

Deletion is a process of removing one or more items from given list. If an array of elements is given and an item is said to remove from specific location. If array is already empty then deletion operation results “Underflow”. To delete the item from array, all the elements from that location are shifted from right to the left side of the Array in this way the element that is to be deleted is overwritten by next element right to the same location. Specific location may in:

1.      Beginning of the Array

2.      Middle anywhere

3.      Last of the Array

Here Lower bound is considered to be as 0.

Array A is given as A[5]={1,2,3,4,5}

           


 

Item to be deleted is 1 on location 0 (i.e. Beginning)

 

New array will be like:


Item to be deleted is 3 on location 2 (i.e. Middle anywhere)

New array will be like:

            d


Item to be deleted is 5 on location 4 (i.e. from Last)

New array will be like:

           

Now from all situations we decrease the size of array by 1 so that last element is removed from Array.

Algorithm DELETEARRAY(A,N,ITEM,LOC)

/*Here DELETEARRAY is an algorithm which is used to delete an ITEM  from the Location LOC in an Array A with N elements. Lower bound of A is considered to be 0. */

 

Step-1 Start

Step-2 set J:=LOC.

Step-3 set ITEM:=A[LOC].

Step-4 Repeat steps 4 and 5 while K<N

Step-5 set A[J]:=A[J+1].

Step-6 set J:=J+1.

Step-7 set N:=N-1.

Step-8 Exit.

 

Conclusion:

An array can also be termed as a collection of homogeneous values. Anybody can treat an array as a single object by referring to it through a variable. Variable name is succeeded by square brackets (that is                  [ ] symbols) But you can also treat the components of the array as if they are themselves variables. Traverse operation is made for going through all elements in an  array. Insert operation is made for adding one or more items in the array. Delete operation is made for removing one or more items in the array.

 

 

No comments:

Post a Comment

Array II Part (Traverse, Insert, Delete Operation)

  Arrays: Operations Traversal, Insertion, Deletion Pankaj Kumar Gupta Head, BCA Department Durga Prasad Baljeet Singh (PG) Colleg...