A program stores values in the list values ← [12, 18, 25, 31]. Which value does values[1] produce?
07. Lists, Arrays, and Sequential Data Online Quiz Questions
Use this free practice quiz with 20 questions to review 07. Lists, Arrays, and Sequential Data, test your knowledge, and prepare for your next test or exam.
True or false: For a list with length 4 using zero-based indexing, index 4 refers to the last element.
- A
True
- B
False
What common list operation adds one element at the end of a collection?
The list is results ← [72, 88, 91]. After executing results[0] ← 79, what is the resulting list?
- A
[79, 88]
- B
[72, 88, 91, 79]
- C
[79, 88, 91]
- D
[72, 88, 91]
A traversal uses total ← 0 and adds each value in numbers ← [4, 8, 15] to total. After the traversal, total is .
Select all statements that correctly describe collection-processing patterns.
- A
Filtering can place only qualifying elements into a new list.
- B
In-place modification always leaves the original list unchanged.
- C
Transformation can create a new value for each original element.
- D
Filtering must change every element in the original list.
True or false: A value-only loop such as for each value in numbers is sufficient by itself to replace every original list element with a modified value.
- A
True
- B
False
A sequential search examines items ← [12, 7, 19, 4] for the target 19. What zero-based index should the search return?
A list may contain only negative values: numbers ← [-8, -15, -2, -11]. If an algorithm correctly finds the maximum by initializing from the first element, what maximum should it produce?
- A
-8
- B
-2
- C
0
- D
5
In the provided findIndex sequential-search algorithm, searching [12, 7, 19, 4] for 10 returns .
Select all cases that are specifically recommended as useful tests for a list-search or indexing algorithm.
- A
An empty list
- B
A target at the first index
- C
Only a target in the middle of a long list
- D
A target at the last index
- E
A target that does not occur
Explain the differences among filtering, transformation, and in-place modification of a list. For each pattern, describe what happens to the original collection and give the essential relationship between the input and output elements.
Given grades ← [[80, 90, 85], [75, 88, 92]], which value does grades[1][2] produce?
- A
80
- B
90
- C
92
- D
75
A list has length 5 and uses zero-based indexing. What is its last valid index?
- A
0
- B
4
- C
5
- D
6
Given results ← [72, 88, 91], the statement results[0] ← 79 is executed. What is the resulting list?
- A
[79, 72, 88, 91]
- B
[72, 88, 91, 79]
- C
[79, 88, 91]
- D
[72, 79, 88, 91]
A filtering algorithm appends a score to passing only when score >= 60. If scores = [72, 55, 91], what is passing after the traversal?
- A
[72, 91]
- B
[55, 72, 91]
- C
[55]
- D
[72, 55, 91]
Using a sequential search that returns the index of the first matching element, what does searching [12, 7, 19, 4] for 19 return?
- A
1
- B
2
- C
3
- D
-1
True or false: For a list of length 4 using zero-based indexing, accessing items[4] is usually invalid.
- A
True
- B
False
An accumulator starts at 0 and traverses numbers = [4, 8, 15], adding each value to total. What final total is produced?
A sequential-search function returns the matching index or -1 when no match exists. What does it return when searching [12, 7, 19, 4] for 10?