Introduction to Data Sets · 使用数据集入门
| English | 中文 | Pinyin · 拼音 |
|---|---|---|
| data structure/ˈdeɪtə ˈstrʌktʃə/ | 数据结构 | shù jù jié gòu |
| array/əˈreɪ/ | 数组 | 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.
许多值,一个名字
- 你常常需要存储许多值——一整个班的分数、一个名字列表。
- 单个变量保存一个值;一个数据结构保存一个集合。
- 一个名字(
scores)加上一个下标或位置就能触及每个值。 - 集合让一个循环一次处理所有的值。
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.
数组与列表
- 数组是一个固定大小的值的集合,全部同一类型。
- ArrayList 是一个可变大小的列表——它能随你添加或删除而增长和缩小。
- 两者都在一个名字下存储许多值,并让你遍历它们。
- 第 4 单元在两者上构建算法。
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.
为什么循环钟爱集合
- 一个集合加一个循环是几乎每个数据任务背后的模式。
- “把所有分数加起来”“找最大的”“数及格的”——都是一个循环。
- 第 2 单元里同样的累加器/最大值/计数模式直接适用。
- 没有集合,你就得为每个值弄一个单独的变量。
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.
从一维到二维
- 一维集合是简单的一行值。
- 二维数组存储一个网格(行和列)——像电子表格或棋盘。
- 嵌套循环(第 2 单元)遍历一个二维网格。
- 第 4 单元依次讲数组、ArrayList 和二维数组。
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.
集合存储许多值,但你仍然按位置触及每一个。对数组,那是一个下标(scores[i]);对 ArrayList,是一个 get(i)。选择正确的结构:当数量已知时用固定大小的数组,当它增长或缩小时用 ArrayList。循环才是让集合强大的东西。
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.
存储测验分数:
- 一个值:
int score = 85;——只有一个学生。 - 一个集合:
int[] scores = {85, 90, 78};——一个名字里一整个班。 - 然后一个循环可以对它们全部求和、平均或搜索。
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.
一个数据结构在一个名字下存储值的集合,按下标或位置触及,从而一个循环能处理它们全部。数组是固定大小、同一类型的;ArrayList 是可变大小的。第 4 单元在数组、ArrayList 和二维数组上构建算法。
A collection of values under one name · 一个名字下的一批值
scores holds many values; an index reaches each one. · scores 保存许多值;下标触及每一个。
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. · ArrayList 可变大小;普通数组固定大小。
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). · 你通过一个值在数组中的 ___(填英文一词,它的位置编号 index)来触及它。
The index is the position of a value in an array. · 下标是一个值在数组中的位置。