Arrays / Lists
Course: Intro Class - DSA - chapter 3
Collection of elements of some (any) type is called an array / list

As mentioned above, the type of elements can be fixed or different depending on the language. For strongly types languages like C++, Java etc you need to specify the type of element the array will be holding. However for some languages (generally weakly typed ones) allow you to have heterogeneous arrays i.e a single array can hold different values (ex - Python, JS)

💡 Python is not weakly typed. It does determine types and runtime and restrict some operations like 10 + “20”. However, it does support heterogeneous arrays.
Operations
Section titled “Operations”Creating an array / list
- For strongly typed languages you need to provide a type
- You can also specify the size of the array / list
- If you don’t specify the size, it creates a dynamic array
C++ code
int arr[10]; // Fixed size
int arr[n]; // Dynamic size. Determined at runtime.
int *arr = new int[n]; // Dynamic size. Determined at runtime.
vector<int> arr; // Completely dynamic. You can add / remove and its size adjustsJS code
const arr = []const arr = [1, 2, 3, 4]const arr = new Array(5) // Not fixed sizeAccess array element using index

Iterating on the elements
You can choose to iterate through all the elements of the array. Generally you go left to right or right to left, one element at a time.
Update the value at any index
Using an index, you can update the array value at that index. You can only do this for mutable arrays / lists however.