INFO
A linear data structure used to store multiple values in a single variable. Arrays are foundational in programming and support indexed access, making them ideal for iteration, sorting, and manipulation.
Array Lists
Properties
- Indexed: each element has a position starting from
0 - Fixed or dynamic size depending on language
- Mutable in most languages—elements can be updated or removed
- Can store homogeneous or heterogeneous types depending on language
- Often used as the basis for more complex structures like matrices, heaps, and hash tables
Common Operations
- Access: Retrieve an element by index (
arr[2]→ third item) - Update: Modify an element (
arr[1] = 42) - Append: Add to the end (
arr.append(5)orarr.push(5)) - Insert: Add at a specific index (
arr.insert(2, "x")) - Delete: Remove by index or value (
del arr[0],arr.remove("x")) - Slice: Extract a sub-array (
arr[1:4]) - Length: Count elements (
len(arr)orarr.length) - Sort: Rearrange elements (
arr.sort())