Written by

Sonal Moga

What is an Array?

Arrays are the linear data structures and they are represented in memory through contiguous memory locations. It is one of the simplest kinds of data structures. Understanding of an array is crucial as arrays are the key to creating any new data structure.

We can declare and define multiple variables of the same type with an identifier using arrays. 

For e.g, int a [5] is a declaration of 5 variables that are put together.

All the basic operations like traversal, search, insertion, deletion, sorting & merging are possible in an array.

Traversal in an array is quite simple and all the elements of an array can be accessed using any simple loop.

Search operation is exactly the literal meaning of the word where we look for a specific item/entity in the array. Search operation can be of two types:

  • Sequential Search is a simple and plain way of searching where all the elements are checked in a sequence until the targeted item is not found. In case of the absence of the looked item, an appropriate message should be returned.
  • Binary Search, on the other hand, divides the array into two equal parts and then compares the needed entity to the middle entity present in the array. If its value is less than the middle one, it looks in the upper half of the array and doesn’t even bother checking the second part and vice versa.

Binary search is said to be more efficient in the two search techniques but has its challenge as well. Binary search can only work on an already sorted array; however, a sequential or linear search can work in both kinds of arrays but is more time-consuming.

Types of arrays

There are essentially two types of arrays,

  • One Dimensional Array, it is a group of contiguous memory locations enclosed in one square bracket, subscripts referred to a common name.
  • Multi-Dimensional Array is an array with more than one subscript.

We can discuss the types of arrays in detail in the next article.