DoRevision

Array Architect

One name for many values, one row per record, and a grid that turns out to have the same shape as a database table. Where that resemblance stops is the part worth knowing.

⏱️ 18 min 🎯 14 activities
Best used for
Homework Independent study Mock preparation

Get the method right under pressure

Free interactive practice on the steps that lose marks under exam pressure.

Start revising free

What you'll cover

One name for many values

Suppose a program needs fifty temperatures. You could declare fifty variables and give each one its own name, and it would work. ⚠️ It would also be useless, and the reason is not that it looks untidy. It is that a loop cannot walk fifty separately named variables. A loop repeats one instruction over and over, changing something small each time, and what it changes is a number. So the values have to be reachable BY NUMBER, which means they need one name between them and a position each. That is what an array is for. One name, many values, each at a numbered position, and therefore a loop that can do the same job to every single one of them in three lines instead of fifty. This module climbs from there: one name for many values, then one row per record, then a grid that turns out to have a very familiar shape.

Words for arrays and records

Six terms. Note what the fourth one says about how positions are written, because it is a choice rather than a law.

Many of the same, or several about one

Counting dimensions is not the useful question. Asking what the items ARE gets you to the right structure every time.

How to choose a structure

Questions on this topic hand you a situation and ask what to store it in. There are two questions that settle it, and they are worth asking in this order. First: are these all the same kind of thing, or are they different things about one subject? That single question does most of the work. Second: will you want to do the same job to each of them, one after another? If yes, they need to be reachable by number, because that is what lets a repeat do the work. Same kind, same job, in turn: one name and numbered positions. Different facts about one subject: separate named parts. ⚠️ Then say WHY, not just which. Naming a structure is worth very little, because the question usually gives you three to choose from anyway. The mark is in the clause that says what it was about THIS data that made that the right choice - and if you cannot write that clause, you have guessed rather than chosen.

Match each situation to what it needs

  • The scores of 30 students in one test
  • One student's name, form group and date of birth
  • The scores of 30 students across 5 different tests
  • A single running total that changes as the program works
  • many values of the same kind, reached by position, so a one-dimensional array
  • several different facts about one subject, each separately named, so a record
  • a grid needing two numbers to reach a value, so a two-dimensional array
  • nothing to hold together at all, so an ordinary single variable

Why not just fifty variables

A program has to store fifty temperature readings and then print every one of them. Why is an array a better choice than fifty separately named variables?

  • A loop can work through an array position by position, while fifty separate names would need fifty separate lines
  • An array uses noticeably less memory than fifty variables would
  • Variables cannot hold numbers, only text
  • An array puts its values into order automatically

The grid that behaves like a table

Five students, three tests each. Store it as a two-dimensional array, and remember the convention this module uses: the first number is the row, the second is the column. Read across one row and you have one student's three marks: everything about one subject, which is a record. Read down one column and you have one test as taken by everybody: the same fact about every subject, which is a field. ⚠️ Now look at what you have actually built. Rows are records. Columns are fields. Every row has the same shape. That is precisely the shape of a database table, and your specification says so directly: a two-dimensional array can be used to emulate one. ⚠️ And here is where the resemblance stops, which is the part worth knowing. A table in a real database can be ASKED things - give me everyone who scored above sixty, sorted by name. A 2D array holds that data perfectly well and cannot answer a single question about it by itself; you would have to write the loop yourself. Asking questions of stored data is querying, and querying is its own topic on this specification. Holding the shape is not the same as having the power.

How many cells in the grid

A two-dimensional array stores the marks of 5 students across 3 tests, with one row per student and one column per test. Multiply to find how many individual marks the grid holds altogether.

Total one student's row

Row 0 of the grid holds one student's three marks: 7, 5 and 8. Trace the loop that adds them up, filling in the value of total after each pass.

Complete the arrays and records paragraph

A structure that holds many values of the same kind under a single name is an _____, and you reach any one of those values by giving its _____. A structure that holds several different pieces of information about one subject, each part carrying its own name, is a _____, and each named part of it is called a _____.

array index record field variable table loop grid

Array or record

Five in a row, three lives. Decide from what the items ARE, not from how many of them there are.

Spot the true array facts

Tap the TWO statements that are true.

  • An array holds many values of the same kind under one name
  • In a grid with one row per record, a column holds one field as it appears for every record
  • A record holds many values of the same kind, reached by position
  • An array puts its values into order automatically

Three storage choices

Three decisions. Each answer has to carry the reason as well as the structure.

  • A program stores the rainfall recorded on each day of a year and then prints the highest figure. What should it use, and why?
  • A program stores a library book's title, its author, the year it was published and whether it is currently on loan. What should it use, and why?
  • A classmate looks at your grid of student marks and says "that is basically a database". What is missing from that?

Explain arrays, records and the grid

A friend has been told that a 2D array "is just a database" and has built their whole revision around it. Write them the answer that sorts out what is true and what is not.

  • Explain what an array is and how you reach one of the values inside it
  • Explain what a record is, and how it differs from an array in what it holds
  • Explain what a two-dimensional array holds, and state which indexing convention you are using
  • Explain how a two-dimensional array can hold the same shape of data as a database table
  • Finish by saying what a database can do that the array cannot, and which topic that belongs to