Array Creation, Traversal, and Algorithms
Free AP Computer Science A multiple-choice practice for topics 4.3–4.5, Unit 4 (Data Collections). Answer five random questions, check your work, and review the essential knowledge behind each one.
Unit 4: Data Collections. Topics 4.3–4.5. This set has 60 questions. Each time the page loads you get five of them, chosen at random. Pick an answer, press Check answer, and read the explanation for every choice. Reload the page or use New questions for a fresh five.
Topics assessed
- 4.3 Array Creation and Access
- 4.4 Array Traversals
- 4.5 Implementing Array Algorithms
Practice questions
Loading questions…
Essential knowledge for this set
These are the essential knowledge (EKS) statements from the AP Computer Science A Course and Exam Description that the 60 questions in this set assess, grouped by topic and learning objective. The table under each question links here.
Topic 4.3: Array Creation and Access
4.3.A — Develop code used to represent collections of related data using one- dimensional (1D) array objects.
- 4.3.A.1 An array stores multiple values of the same type. The values can be either primitive values or object references.
- 4.3.A.2 The length of an array is established at the time of creation and cannot be changed. The length of an array can be accessed through the length attribute.
- 4.3.A.3 When an array is created using the keyword new, all of its elements are initialized to the default values for the element data type. The default value for int is 0, for double is 0.0, for boolean is false, and for a reference type is null.
- 4.3.A.4 Initializer lists can be used to create and initialize arrays.
- 4.3.A.5 Square brackets [] are used to access and modify an element in a 1D array using an index.
- 4.3.A.6 The valid index values for an array are 0 through one less than the length of the array, inclusive. Using an index value outside of this range will result in an ArrayIndexOutOfBoundsException.
Topic 4.4: Array Traversals
4.4.A — Develop code used to traverse the elements in a 1D array and determine the result of these traversals.
- 4.4.A.1 Traversing an array is when repetition statements are used to access all or an ordered sequence of elements in an array.
- 4.4.A.2 Traversing an array with an indexed for loop or while loop requires elements to be accessed using their indices.
- 4.4.A.3 An enhanced for loop header includes a variable, referred to as the enhanced for loop variable. For each iteration of the enhanced for loop, the enhanced for loop variable is assigned a copy of an element without using its index.
- 4.4.A.4 Assigning a new value to the enhanced for loop variable does not change the value stored in the array.
- 4.4.A.5 When an array stores object references, the attributes can be modified by calling methods on the enhanced for loop variable. This does not change the object references stored in the array.
- 4.4.A.6 Code written using an enhanced for loop to traverse elements in an array can be rewritten using an indexed for loop or a while loop.
Topic 4.5: Implementing Array Algorithms
4.5.A — Develop code for standard and original algorithms for a particular context or specification that involves arrays and determine the result of these algorithms.
-
4.5.A.1 There are standard algorithms that utilize array traversals to:
- determine a minimum or maximum value
- compute a sum or average
- determine if at least one element has a particular property
- determine if all elements have a particular property
- determine the number of elements having a particular property
- access all consecutive pairs of elements
- determine the presence or absence of duplicate elements
- shift or rotate elements left or right
- reverse the order of the elements