Introduction
In this lesson, we'll go over some basic array concepts, most of which you might already know.
Arrays
Arrays are an integral part of many advanced algorithms and data structures. Many of them will require you to know how to perform operations, how to perform optimizations, and what the limitations are.
We’ll go over some commonly used terms and their meaning.
Subarray
A subarray is a contiguous part of the array. I’ll be using this notation to denote subarray . This represents a subarray of the array containing all the elements from to index, both inclusive. For example:
An array of size has an order of subarray. to be exact.
subarrays of size and subarrays of size > 1 (Pick any 2 index)
Subsequence
A subsequence of an array can be obtained by deleting some (or none, or all) elements of the original array without changing the order of elements. For example:
Few subsequences for are , including an empty array .
is not a subsequence because the order is not the same as the original array.
An array of size has subsequences, meaning for each element in the array, we have 2 choices (keep it or remove it).
Contiguous memory allocation
Array elements occupy contiguous memory blocks, and we have the following properties as a result:
Element access is operation
Since we know the starting address, any arbitrary element’s address is simple arithmetic.
Inserting element in between is operation
Consider you have an array of size allocated and it only has elements . To insert an element at position , we have to shift to the right by one place. In the worst case, we’ll have to shift the entire array (N operations).
Get hands-on with 1400+ tech skills courses.