Arrays

An array is a collection of elements of the same data type, stored sequentially in memory. Each element can be accessed directly using an index, which represents its position within the array. Arrays are a fundamental data structure in computer science, with native support in programming languages like C, C++, Java, JavaScript, Python, and more.

Common algorithms done on arrays are searching and sorting. Some of the most efficient array search algorithms, like binary search, assume the array is sorted beforehand.

A subarray is a contiguous subset of an array. For example, given the array [2, 6, 1, 10, 7, 14, 3], a subarray would be [1, 10, 7].

A subsequence of an array means deleting some or no elements without changing the overall order. A subsequence of the above array might be [6, 10, 7], but not [10, 6, 2].

Navigation Using Initial Address

Given an array of five 2-byte elements located at memory location 1000, the memory location of the i-th element can be found using the equation 1000 + (i x 2). In other words, the memory location of the fourth element (index 3) will be 1000 + (3 x 2) = 1006. Note that because this equation doesn't depend on the size of the array - only its initial memory address and element size - accessing arbitrary elements in an array is an O(1) operation.

Advantages of Arrays

Disadvantages of Arrays