Introduction to Arrays in Computer Science: 1D, 2D, and Multi-Dimensional Arrays, Slides of Computer science

This resource introduces arrays in computer science, covering one-dimensional and two-dimensional types. It provides examples of array declaration and usage, along with trace tables for understanding element access and manipulation. Multi-dimensional arrays and their applications are also discussed. Suitable for high school students learning programming fundamentals, it offers a foundational understanding of arrays as a crucial data structure. Pseudocode examples and trace tables illustrate array manipulation, helping students grasp data structure basics and their implementation in problem-solving. The content builds from basic data types to complex array structures, making it accessible for beginners, with examples and exercises to enhance learning.

Typology: Slides

2024/2025

Uploaded on 07/20/2025

politics-now
politics-now 🇬🇧

5 documents

1 / 17

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
4
AQA
AS Level
Computer
Science
Paper 1
Arrays
Unit 1
Fundamentals
of programming
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Introduction to Arrays in Computer Science: 1D, 2D, and Multi-Dimensional Arrays and more Slides Computer science in PDF only on Docsity!

AQA

AS Level

Computer

Science

Paper 1

Unit 1 Fundamentals of programming

Objectives

  • (^) Be familiar with the concept of a data structure
  • (^) Use 1- and 2-dimensional arrays in the design of

solutions to simple problems

Unit 1 Fundamentals of programming An array of names

  • (^) If you need to sort, for example, 100 names of towns

into alphabetical order, it is inconvenient to have

different names town1, town2, town3 to hold them

  • (^) Instead, they are all given one name, and referred to

by an index as, for example, town(1), town(2) …

town(n)

  • (^) In some languages such as Python, the first element

of the array is referred to as town[0], and square

brackets are used

Unit 1 Fundamentals of programming Referencing array elements

Follow the pseudocode and complete the trace table

name1  Joe name2  Jim names(1)  Moe names(2)  Mae names(3)  Mic FOR i  1 to 3 OUTPUT names(i) ENDFOR OUTPUT name OUTPUT name names name1 name2 1 2 3 i OUTPUT

Unit 1 Fundamentals of programming Arrays of numbers

  • (^) Arrays can also hold numbers
  • (^) What does this algorithm do? FOR i  1 to 3 mark(i) USERINPUT total total + mark(i) ENDFOR avg total / 3 OUTPUT avg OUTPUT “3rd mark”,mark(2) Mark 1 2 3 i total avg OUTPUT Use test data: mark(0)=10, mark(1)=15, mark(2)=

Unit 1 Fundamentals of programming Arrays of numbers

  • (^) Arrays can also hold numbers
  • (^) What does this algorithm do? FOR i  1 to 3 mark(i) USERINPUT total total + mark(i) ENDFOR avg total / 3 OUTPUT avg OUTPUT “3rd mark”,mark(2) mark 1 2 3 i total avg OUTPUT 10 1 10 - - 10 15 2 25 - - 10 15 20 3 45 - - 10 15 20 - 45 15 - 10 15 20 - 45 15 15 10 15 20 - 45 15 3 rd^ mark 20 Use test data: mark(1)=10, mark(2)=15, mark(3)=

Unit 1 Fundamentals of programming 1D arrays

  • (^) At GCSE we’d combine 2 arrays to get data city = [“London” , “Manchester” , ”Birmingham”] cityPop = [“8.6” , “2.5” , ”2.4”] 2D arrays
  • (^) It is also possible to have two-dimensional arrays city = [[“London” , ”8.6”],[“Manchester”, “2.5”] , [”Birmingham”, “2.4”]]

Unit 1 Fundamentals of programming 2D arrays grid = [] for i in range (2): for j in range(2): grid.append ([i,j]) print(grid) Write down what this will output.

Unit 1 Fundamentals of programming 2D array trace table

  • (^) Fill in the trace table if the user inputs

a, b, c, x, y, z

  • (^) Don’t forget to fill in i and j letters = [] FOR i = 1 to 2 FOR j = 1 to 3 letters(i, j)  USERINPUT ENDFOR ENDFOR Letters (1,1) (1,2) (1,3) (2,1) (2,2) (2,3) i j a 1 1 b 1 2 c 1 3 x 2 1 y 2 2 z 2 3

Unit 1 Fundamentals of programming Arrays

grid = [i for i in range(10)]

print (grid)

grid = [[i,j] for i in range(3) for j in range(3)]

print (grid)

Unit 1 Fundamentals of programming Multi-dimensional arrays

  • (^) It is possible to define arrays with any number of

dimensions

  • (^) The array is a set of elements with the same data

type

  • (^) For example, you could have a 3-dimensional array which would hold x, y and z coordinates in 3-D space
  • (^) You could use a 4-dimensional array to hold sales for branches of a supermarket, by country, store, department, and year

Unit 1 Fundamentals of programming Plenary

  • (^) An array is a data structure containing multiple

elements all of the same data type, e.g. string,

integer, real, etc.

  • (^) Elements of the array are accessed using an index,

which typically starts at 0

  • (^) An array can have several dimensions
  • (^) A 2-dimensional array can be used to represent a

grid of rows and columns