Kablow!

Arrays, lists and records

Học bằng cách chơi

Trả lời những câu hỏi này để kiếm năng lượng, rồi câu cá và khám phá. Không cần tài khoản.

Dành cho nhà giáo dục: slide bài học, ghi chú ôn tập sẵn dùng cho Arrays, lists and records (Computer Science, Programming) — dùng trong bài giảng của bạn, hoặc chạy chủ đề như một hoạt động lớp học tương tác để người học chơi như một trò chơi trực tiếp.

Ghi chú bài học

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

Slide

Sign up free to view the lesson slides

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

Câu hỏi luyện tập

Xem trước miễn phí — 8 trên 33 câu hỏi. Đăng ký để xem tất cả.
  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

Tạo tài khoản miễn phí để xem mọi câu hỏi, slide, thẻ ghi nhớ và ghi chú ôn tập cho chủ đề này.

Đề thi cũ

Luyện đề thi cũ cho chủ đề này sắp ra mắt.
Sắp ra mắt