Kablow!

Arrays, lists and records

Lerne es beim Spielen

Beantworte diese Fragen für Energie, dann angle und erkunde. Kein Konto nötig.

Für Lehrkräfte: sofort einsetzbare Lektionsfolien, Lernnotizen für Arrays, lists and records (Computer Science, Programming) — nutze sie in deiner Lektion oder starte das Thema als interaktive Klassenaktivität, die deine Lernenden als Live-Spiel spielen.

Lektionsnotizen

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

Folien

Sign up free to view the lesson slides

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

Übungsfragen

Gratis-Vorschau — 8 von 33 Fragen. Registriere dich, um alle zu sehen.
  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

Erstelle ein Gratis-Konto, um alle Fragen, Folien, Karteikarten und Lernnotizen zu diesem Thema zu sehen.

Altklausuren

Altklausuren-Übungen für dieses Thema kommen bald.
Bald verfügbar