Kablow!

Arrays, lists and records

Apprends en jouant

Réponds à ces questions pour gagner de l'énergie, puis pêche et explore. Sans compte.

Pour les enseignants : diapos de leçon, notes de révision prêts à l'emploi pour Arrays, lists and records (Computer Science, Programming) — utilise-les en cours, ou lance le thème en activité de classe interactive que tes apprenants jouent en direct.

Notes de leçon

Arrays and lists

  • An array stores multiple values of the same data type under one name. Each item has an index (usually starting at 0). Example: scores = [12, 8, 15]; scores[0] is 12.
  • One-dimensional (1D) arrays are lists; two-dimensional (2D) arrays are tables with rows and columns: grid[row][column].
  • Arrays have a fixed size in many languages; lists may grow.

Indexed array

Indexed array

Using arrays

  • Traversal visits elements using their valid indices. For total = 0 and scores = [12, 8, 15], an inclusive FOR loop from 0 to 2 adds all three elements to give 35.
  • Initialise an accumulator before adding values. For a maximum search, initialise from the first element of a non-empty array rather than assuming zero is a valid starting maximum.

Array traversal

Array traversal

Records

  • A record groups named fields about one entity, such as a student’s name, age and grade. Fields may have different types.
  • Collections of records may be held in files or database tables; not every record file by itself is a database system.

When to use

  • Use arrays for lists of the same type; records for related fields of different types.

Advantages

  • Arrays avoid many separate variables, make code shorter and loops possible.

Two-dimensional arrays

  • grid[row][column]
  • Rows and columns
  • Nested loops

Accessing a two-dimensional array

Accessing a two-dimensional array

Diapos

Sign up free to view the lesson slides

Step through every slide for this topic — plus flashcards and revision notes — with a free account.

Questions d'entraînement

Aperçu gratuit — 8 sur 33 questions. Inscris-toi pour toutes les voir.
  1. 1.What is an array?

    Easy
    • Aa data structure storing multiple values under one name
    • Ba variable only
    • Ca loop
    • Da function
  2. 2.What is an index?

    Easy
    • Athe position of an item in an array
    • Bthe value
    • Cthe size
    • Dan error
  3. 3.With zero-based indexing, which index selects the first item?

    Easy
    • A0
    • B1
    • C-1
    • D2
  4. 4.What is a record?

    Easy
    • Aa collection of fields about one thing
    • Ba list of numbers
    • Ca loop
    • Da file name
  5. 5.What is a field?

    Easy
    • Aone item of data in a record
    • Ba loop
    • Ca function
    • Dan array
  6. 6.If names = ["Ali","Bo","Cy"], what is names[2]?

    Easy
    • A"Cy"
    • B"Bo"
    • C"Ali"
    • Derror
  7. 7.What is the length of [4, 7, 9, 2]?

    Easy
    • A4
    • B3
    • C5
    • D2
  8. 8.a is a zero-based array of three numbers. What does this inclusive loop do? total = 0; FOR i = 0 TO 2; total = total + a[i]; NEXT i

    Easy
    • Aadds all three elements
    • Bdeletes elements
    • Csorts them
    • Dfinds the largest

Unlock all 33 questions & more

Crée un compte gratuit pour voir toutes les questions, les diapos, les cartes mémo et les notes de révision de ce thème.

Annales

Les annales d'entraînement pour ce thème arrivent bientôt.
Bientôt disponible