Sitemap
Shiny R . A

Shiny R . A

Student aspiring to become a software engineer .

ARRAYS

2 min readMay 12, 2020

Array is a data structure which holds same type of fixed number of data elements . Most of the other data structures like stack or queue make use of arrays to implement their algorithms .

Important terms in arrays : 1. Element : Each item stored in an array is called an element .

2.Index: Each location of an element in an array has a numerical index, which is used to identify the element.

Array declaration : In C , array is declared as below example .

Press enter or click to view image in full size
array representation

Array can be declared in different ways in different languages .

illustration of an array

Important points to be considered are :

  1. Index starts with 0 . (not 1 )
  2. In above example , array length is 10 , since it can store 10 elements .
  3. Each element can be accessed using it’s index . ( array[5] is element stored at index 5 in array , which is 19 )

Basic operations on an array :

  1. Insertion : Adding elements in an array at a given index.
  2. Deletion : Deletes elements in an array at a given index .
  3. Search : Searches an elements using either index or value .
  4. Traverse : Printing all elements in an array one by one .
  5. Update : Update an element at the given index .

When an array is initialized with size , then it assigns default values as 0 for all data types , false for boolean data type , and null for object type .

Get Shiny R . A’s stories in your inbox

Join Medium for free to get updates from this writer.

Advantages of an Array:

  • We can put in place other data structures like stacks, queues, linked lists, trees, graphs, etc. in Array.
  • Arrays can sort multiple elements at a time.
  • We can access an element of Array by using an index.

Disadvantages of an Array :

  • We have to declare Size of an array in advance. However, we may not know what size we need at the time of array declaration.
  • The array is static structure. It means array size is always fixed, so we cannot increase or decrease memory allocation.

This is the introduction of Arrays .

--

--

Shiny R . A
Shiny R . A

Written by Shiny R . A

Student aspiring to become a software engineer .