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.

Editor — Python
Output
No output yet.

PSEUDOCODE

Pseudocode uses basic Cambridge-style keyword highlighting. Execution is not supported yet.

Editor — Pseudocode

Common Array Operations

PYTHON

Python can be executed directly in the browser.

Editor — Python
Output
No output yet.

PSEUDOCODE

Pseudocode uses basic Cambridge-style keyword highlighting. Execution is not supported yet.

Editor — Pseudocode

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.

Editor — Python
Output
No output yet.

PSEUDOCODE

Pseudocode uses basic Cambridge-style keyword highlighting. Execution is not supported yet.

Editor — Pseudocode

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.

Editor — Python
Output
No output yet.

PSEUDOCODE

Pseudocode uses basic Cambridge-style keyword highlighting. Execution is not supported yet.

Editor — Pseudocode

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 1Student 2Student 3
Physics909179
Chemistry805060
Maths826775
Computer Science789295

This can be represented in Python as the following

PYTHON

Python can be executed directly in the browser.

Editor — Python
Output
No output yet.

PSEUDOCODE

Pseudocode uses basic Cambridge-style keyword highlighting. Execution is not supported yet.

Editor — Pseudocode