Subtopic Notes
8.2 - Arrays
8. Programming
Arrays
- Stores a collection of elements of the same data type
- Contiguous block of memory
- Widely used in programming because they allow efficient access and manipulation of a large number of values
- Elements can be accessed using index
- Arrays are 0 indexed: Index of 1st element is 0, 2nd element is 1
- Index of last element: length - 1
- In Pseudocode, Arrays index might start from 0 or 1
PYTHON
Python can be executed directly in the browser.
No output yet.
PSEUDOCODE
Pseudocode uses basic Cambridge-style keyword highlighting. Execution is not supported yet.
Common Array Operations
PYTHON
Python can be executed directly in the browser.
No output yet.
PSEUDOCODE
Pseudocode uses basic Cambridge-style keyword highlighting. Execution is not supported yet.
Linear Search
Simple searching algorithm that checks each element in a list or array sequentially until it finds the desired value
PYTHON
Python can be executed directly in the browser.
No output yet.
PSEUDOCODE
Pseudocode uses basic Cambridge-style keyword highlighting. Execution is not supported yet.
Bubble Sort
Sorting algorithm that repeatedly swaps adjacent elements if they are in the wrong order and iterates until the list is sorted.
PYTHON
Python can be executed directly in the browser.
No output yet.
PSEUDOCODE
Pseudocode uses basic Cambridge-style keyword highlighting. Execution is not supported yet.
2D Arrays
- Type of array where each element is itself an array
- Can be visualized as a table with rows and columns,
- Ideal for representing grid-like structures such as matrices, game boards or spreadsheets
Example
A 2D array to store student grades for 4 subjects and 3 students.
| Student 1 | Student 2 | Student 3 | |
|---|---|---|---|
| Physics | 90 | 91 | 79 |
| Chemistry | 80 | 50 | 60 |
| Maths | 82 | 67 | 75 |
| Computer Science | 78 | 92 | 95 |
This can be represented in Python as the following
PYTHON
Python can be executed directly in the browser.
No output yet.
PSEUDOCODE
Pseudocode uses basic Cambridge-style keyword highlighting. Execution is not supported yet.
