Revise Computingrevisecomputing.co.uk
At a glanceFeaturesStudentsPricingHow it worksFree GCSE notesExam dates
At a glanceFeaturesStudentsPricingHow it worksFree GCSE notesExam dates

Knowledge organisers / Additional Programming Techniques

The use of arrays (or equivalent) when solving problems: one-dimensional (1D)

All topicsPractise exam questions
Knowledge organiser

Additional Programming Techniques

2.2.3f

Arrays as fixed length or static structures

What you need to know

A one-dimensional (1D) array is a data structure that stores a fixed-size collection of elements of the same data type under a single name. Each element is accessed using an index (position number), starting from 0. Arrays are static, meaning their size cannot change once they are created.

Key points

  • Arrays store multiple items of the same data type under one name.
  • Elements are accessed using an index, starting from 0 (zero-indexed).
  • Arrays are static (fixed size): their length is set when created and cannot change.
  • Declaring: array names[5] creates an array with 5 elements (index 0 to 4).
  • Assigning: names[0] = "Alice" puts "Alice" at position 0.
  • Arrays are useful for storing lists of data, e.g. scores, names, or colours.
  • You can loop through an array using a FOR loop: for count = 0 to theTeam.length - 1.
  • Exam Tip:A FOR loop iterating through an array should use the loop counter as the INDEX: theTeam[count], NOT theTeam[i] if the counter is called count.
  • Exam Tip:Off-by-one errors are common. If the array has 6 elements (index 0-5), the loop should go 0 to 5. Python's range(6) gives 0-5.
  • Exam Tip:theTeam.length returns the number of elements. To loop from 0, use for i = 0 to theTeam.length - 1.
  • Exam Example:Linear search fills: for count = 0 to theTeam.length - 1; if theTeam[count] == studentName then return True. Use the COUNTER as the array INDEX.
  • Exam Tip:scores = [3, 6, 6, 9, 2, 8] → scores[2] = 6 (third element, 0-indexed). Remember arrays are ZERO-INDEXED.

Code examples

1D array operations
python
# Create and access a 1D array (list in Python)
scores = [10, 20, 30, 40, 50]

print(scores[0])   # 10 (first element)
print(scores[2])   # 30 (third element)
scores[1] = 25     # Update second element

# Loop through the array
for i in range(len(scores)):
    print("Index " + str(i) + ": " + str(scores[i]))