Open In App

Array Definition & Meaning in DSA

Last Updated : 31 Mar, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

An array is a collection of items of same data type stored at contiguous memory locations

Array example

Array example

Types of Arrays:

  • One-dimensional Array: It is the simplest kind of array where all the elements are stored linearly in a single row. 
  • Two-dimensional Array: A two-dimensional array is an array with 2 dimensions, i.e., each unique element is accessed using two iterators. In simple terms, it can be visualised as a matrix.
  • Multi-dimensional array: An array with more than two dimensions, is referred to as a multi-dimensional array.
  • Static array: An array with a fixed size that is chosen at compile time is referred to as a static array. A static array’s size cannot be altered at the run time.
  • Dynamic array: A dynamic array is one that has a variable size that can be altered while it is being used. Pointers and memory allocation algorithms are used in its implementation.
  • Jagged array: A jagged array is an array of arrays such that member arrays can be of different sizes.
  • Sparse array: A sparse array is one with a large percentage of empty or zero elements. It is employed to optimise memory usage in applications that call for sizable arrays with a large percentage of empty values.

Properties of Array:

An array has the following features or properties:

  • Homogeneous Data: Only one data type can be stored in an array at a time. As a result, every element in an array needs to have the same data type.
  • Fixed Size: Since arrays have a fixed size, the number of elements they can contain cannot be changed after they have been created. Dynamic arrays, on the other hand, can change in size while a programme is running in some programming languages.
  • Contiguous Memory Allocation: Any element in an array can be accessed by using its index because all of the elements are stored in contiguous memory locations.
  • Indexed: Arrays are indexed data structures, each element in an array has a corresponding index.
  • Efficient Access: It takes a constant amount of time, regardless of the array’s size, to access an element within.
  • Mutable: Arrays are mutable data structures, which means that the elements in an array can be modified after the array is created.

Applications of Array:

Arrays are a basic data structure in computer programming that can be used in a variety of applications. Here are some examples of array applications:

  • Storing and accessing data: Arrays are a fundamental data structure that is used to store and retrieve structured data.
  • Sorting and searching algorithms: Sorting and searching algorithms such as bubble sort, insertion sort, merge sort, and quicksort frequently use arrays.
  • Graphs and matrices: Arrays can be used to represent graphs and matrices, which are commonly used in image processing, network routing, and scientific simulations.
  • Implementing data structures: Arrays are used to implement many common data structures such as stacks, queues, and hash tables.
  • Statistical analysis: Arrays are useful for storing data for statistical analysis and calculations like calculating mean, median, and standard deviation.

To learn more about applications of an array, refer to this article.

Advantages of Array:

Arrays are a basic data structure in computer programming that provide several benefits:

  • Contiguous memory allocation: Arrays allocate memory in a contiguous block, which means that all the elements are stored in a single block of memory.
  • Fast access to elements: Since every element in an array is accessed via an index, the time required to access any element is constant time.
  • Efficient memory usage: Arrays typically use less memory than other data structures such as linked lists.
  • Easy to implement: Arrays are easy to implement and understand, making them an ideal choice for beginners learning computer programming.

To learn more about the advantages of an array, refer to this article.

Disadvantages of Array:

While arrays offer several advantages, there are also some disadvantages to using arrays:

  • Fixed size: Arrays have a fixed size, which means that the size cannot be changed once the array is created.
  • Memory wastage: Arrays can waste memory if they are not completely filled with elements.
  • Inefficient deletion: Deleting an element in the middle of an array can be inefficient, as it requires shifting all the elements after the deletion.
  • Homogeneous data type: Arrays can only hold elements of the same data type.

To learn more about the disadvantages of an array, refer to this article.

What else can you read?


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads