Posts

Types of arrays

 

Types of arrays

  • One-dimensional Array
  • Two-dimensional Array
  • Three-dimensional Array

Two dimensional and three dimensional arrays are also called multi-dimensional arrays. in types of arrays, multi-dimensional arrays also include arrays with four and higher dimensions.

One-dimensional Array

In a one-dimensional array the elements are stored in contiguous memory locations where each element is accessed by using a single index value. It is a linear data structure storing all the elements in sequence.

Types of arrays -One dimensional array

The elements are stored in memory in continuation and the variable declared as an array is actually a pointer to the address of first element of the array. This address is called the base address. The address of any other element can be calculated with the following formula

Two-dimensional Array

In types of arrays, a two dimensional array is a tabular representation of data where elements are stored in rows and columns. A two dimensional array is actually a collection of M X N elements which has M rows and N columns.  To access any element in a two-dimensional array two subscripts are required for defining position of an element in a specific row and column. The first index is for row number and second is for column index.  In the example shown the first index values row=2 column=3 is used to access element 56.

Types of arrays -Two dimensional array

Two dimensional arrays are stored in memory in two representations

Three-dimensional Array

In types of arrays, a three-dimensional array is an extension to the two dimensional array with addition of depth. It can be seen as a cube that has rows, columns and depth as third dimension. To access any element in a three-dimensional array three subscripts are required for position of element in a specific row, column and depth. The first index is for depth (dimension or layer), second is for row index and third is for column.  In the example shown the index values (2,0,3)  is used to access element 24.

Types of arrays -3 dimensional array

Post a Comment

© Data structures. The Best Codder All rights reserved. Distributed by