Introduction to Data Sets
| English | Chinese | Pinyin |
|---|---|---|
| data structure | 数据结构 | shù jù jié gòu |
| array | 数组 | shù zǔ |
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.
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.
A collection of values under one name
scores holds many values; an index reaches each one.
A structure that stores many values of the same type under one name is a(n)...
An array is a fixed-size, same-type collection.
Which structure can grow and shrink as you add or remove elements?
ArrayList is resizable; a plain array is fixed-size.
The pattern behind almost every data task is a collection plus a...
A loop processes every value in the collection.
A 2-D array stores values in a grid of rows and columns.
Like a spreadsheet or board; nested loops traverse it.
You reach a value in an array by its ___ (one word, its position number).
The index is the position of a value in an array.