Array in Data Structure

Array in Data Structure:-

  • Array is linear type of data structure.
  • Definition array is a set of similar type of (homogeneous) data.
  • The arrangement in an array in a systematic order as a sequential.
  • An array stored in a systematic order it given and sequential index.
  • Array index start with zero.
  • Each array element can be accessed by its index.

Example:- suppose we have 10 number (similar type integers) are stored in array array1.

Array in Data Structure

As we see array1 is started continuously and its index starts with 0.

Initializing array:-

It specifies the number of element we want to store that is size of array.

Example:- arr[10];

Assigning:-

This operation assigns a value to an array.

Example:- arr[0]=1;
                  arr[1]=2;

The operation performed on array

  1. Adding element
  2. Deleting element
  3. Sorting element
  4. Searching element
  5. Re-arranging element
  6. For performing matrix operation

Advantages of array

  1. Collection of homogeneous element.
  2. It has index.
  3. We can access any element by index.
  4. To implement data structure like stack, queue.

Disadvantages of array

  1. We must know how many element to stored.
  2. The array is fixed size that is memory allocated to array can not be increased or reduced.
  3. As array fixed size, if we allocated more memory then we are using then memory will be wasted.
  4. Element in array are stored in consecutive memory location so insertion and deletion takes more time.

Simple program using array

1234567891011121314#include<stdio.h>void main(){int arr[5],j; // Initilizing arrayprintf(“Enter array:”);for(i=0;i<5;i++) // taking array input{scanf(“%d”,&arr[i]);}printf(“our array”);for(i=0;i<5;i++){printf(“%d”,arr[i]); // Printing our array}

Output of program

Enter array
10 20 30 40 50

our array
10 20 30 40 50array in Data Structure
Array in Data Structure
Array in Data Structure