Giới thiệu về Tập dữ liệu
Đã giới thiệu| English | Ý nghĩa |
|---|---|
| data structure/ˈdeɪtə ˈstrʌktʃə/ | cấu trúc dữ liệu |
| array/əˈreɪ/ | mảng |
Many values, one name
- Often you need to store many values — a whole class's scores, a list of names.
- A single variable holds one value; a data structure 数据结构 holds a collection.
- One name (
scores) plus an index or position reaches each value. - Collections let one loop process all the values at once.
Arrays and lists
- An array 数组 is a fixed-size collection of values, all the same type.
- An ArrayList is a resizable list — it can grow and shrink as you add or remove.
- Both store many values under one name and let you loop over them.
- Unit 4 builds algorithms on both.

A filing cabinet: collections store many values under one name so algorithms can process them
Why loops love collections
- A collection plus a loop is the pattern behind almost every data task.
- "Add up all the scores," "find the biggest," "count the passes" — all one loop.
- The same accumulator/max/count patterns from Unit 2 apply directly.
- Without collections, you'd need a separate variable for every value.
From 1-D to 2-D
- A one-dimensional collection is a simple line of values.
- A 2-D array stores a grid (rows and columns) — like a spreadsheet or board.
- Nested loops (Unit 2) traverse a 2-D grid.
- Unit 4 covers arrays, ArrayLists, and 2-D arrays in turn.
A collection stores many values, but you still reach each one by its position. For an array, that's an index (scores[i]); for an ArrayList, a get(i). Choose the right structure: a fixed-size array when the count is known, an ArrayList when it grows or shrinks. Looping is what makes a collection powerful.
Storing test scores:
- One value:
int score = 85;— only one student. - A collection:
int[] scores = {85, 90, 78};— a whole class in one name. - A loop can then total, average, or search all of them.
A data structure stores a collection of values under one name, reached by index or position, so a loop can process them all. An array is fixed-size and same-type; an ArrayList is resizable. Unit 4 builds algorithms on arrays, ArrayLists, and 2-D arrays.
Một tập hợp các giá trị dưới một tên gọi chung
mảng chứa nhiều giá trị; chỉ số truy cập từng giá trị.
Cấu trúc lưu trữ nhiều giá trị cùng loại dưới một tên gọi là... (a(n)...)
Độ khó 1/5 · 100 xu + một phần thưởng nhỏ cho lần hoàn thành đầu tiên trong ngày
Mảng là cấu trúc có kích thước cố định và cùng kiểu dữ liệu.
Cấu trúc nào có thể mở rộng hoặc thu gọn khi thêm/xóa phần tử?
Độ khó 1/5 · 100 xu + một phần thưởng nhỏ cho lần hoàn thành đầu tiên trong ngày
ArrayList có thể thay đổi kích thước; mảng thông thường có kích thước cố định.
Mẫu hình cơ bản cho hầu hết các tác vụ dữ liệu là: collection cộng với...
Độ khó 1/5 · 100 xu + một phần thưởng nhỏ cho lần hoàn thành đầu tiên trong ngày
Vòng lặp xử lý từng giá trị trong collection.
Mảng 2 chiều lưu trữ giá trị theo dạng lưới hàng và cột.
Độ khó 1/5 · 100 xu + một phần thưởng nhỏ cho lần hoàn thành đầu tiên trong ngày
Giống như bảng tính hoặc bàn cờ; vòng lặp lồng nhau duyệt qua nó.
Bạn truy cập giá trị trong mảng bằng ___ (một từ, là số vị trí của nó).
Độ khó 1/5 · 100 xu + một phần thưởng nhỏ cho lần hoàn thành đầu tiên trong ngày
Chỉ số (index) là vị trí của một giá trị trong mảng.