Basic Operation on Array (Data Structure)

basic operation array

What is an Array?

Definition:

An array is defined as finite ordered collection of Homogeneous data, stored in contiguous memory locations. More about Array..

Two important part of Array

  1. Element         : Each item stored in an array is called an element or value.
  2. Index              : Each location of an element in an array has a numerical index, which is used to identify the element or value. Index value must zero or greater than zero

Array Representation in figure

base address

Array Operations

Following are the various operations supported by an array.

  1. Traverse         : Print all the array elements one by one.
  2. Insertion         : Add an element at given index.
  3. Deletion          : Delete an element at given index.
  4. Search             : Search an element using given index or by value.
  5. Update             : Update an element at given index.

Traverse Operation

In this operation of an array, each element of an array is accessed exactly for once for processing. This is also called visiting of an array.

In short Print all the array elements one by one.

Here is code:

OUTPUT:


Insertion Operation

In this operation is to insert one or more data elements into an array. Based on the requirement, new element can be added at the beginning, end or any given index of array.

Any given index of array

Here is code:

OUTPUT:


Deletion Operation

In this operation is to removing an existing element from the array and re-organizing all elements of an array. Based on the requirement, element can be deleted at the beginning,end or any given index of array

Here is code:

OUTPUT:


Search Operation

In this operation you can perform a search for array element based on its value or its index.

Here is code:

OUTPUT:


Update Operation

In this operation refers to updating an existing element from the array at a given index.

Here is code:

OUTPUT:

Please follow and like us:

Leave a Reply

Your email address will not be published. Required fields are marked *