Free Practice Quiz Question List

6 Arrays and Collections Online Quiz Questions

Use this free practice quiz with 20 questions to review 6 Arrays and Collections, test your knowledge, and prepare for your next test or exam.

20 questions
01
True or false
1 point

True or false: Replacing an existing element in an array changes the array's length.

  1. A

    True

  2. B

    False

02
Choose one
1 point

An array has length 5. Which index is outside the valid range?

  1. A

    0

  2. B

    4

  3. C

    5

  4. D

    6

03
Written response
1 point

Using the linear-search convention described in the material, what integer should linearSearch([14, 7, 22, 9], 11) return?

04
Fill in the blank
1 point

Complete the rule: For an array of length n, the valid indexes range from 0 through .

05
Choose one
1 point

Before applying binary search to an array, which condition is essential?

  1. A

    The array must contain only positive values.

  2. B

    The array must already be sorted using the search ordering.

  3. C

    The array must have a fixed length of exactly n elements.

  4. D

    The array must contain no duplicate values.

06
True or false
1 point

True or false: To find a maximum reliably, an algorithm should initialize its best-so-far value from the first array element rather than assuming that 0 is a suitable starting value.

  1. A

    True

  2. B

    False

07
Choose all
1 point

Select all situations for which the material specifically recommends using an indexed loop.

  1. A

    Use an indexed loop when changing elements in place.

  2. B

    Use a collection-style loop when comparing neighboring positions.

  3. C

    Use an indexed loop when the index is needed.

  4. D

    Use a collection-style loop when the array must be sorted first.

08
Written response
1 point

What is the average of the array [72, 88, 61, 95]?

09
Fill in the blank
1 point

Complete the statement: A traversal that visits every element of an array with n elements has running time approximately .

10
Choose all
1 point

Select all statements that correctly describe the set-based approach to detecting duplicates.

  1. A

    A set can record values already seen.

  2. B

    The set-based approach always uses O(1) extra space.

  3. C

    The set-based approach can improve the time to approximately O(n).

  4. D

    The set-based approach requires the input to be sorted first.

11
Choose one
1 point

Which statement correctly describes JavaScript's sort() method according to the material?

  1. A

    JavaScript's sort() always leaves the original array unchanged.

  2. B

    JavaScript's sort() changes the array on which it is called.

  3. C

    JavaScript's sort() is valid only for already sorted arrays.

  4. D

    JavaScript's sort() returns a separate result while toSorted() mutates the original.

12
Choose one
1 point

Which strategy best implements containsDuplicate(values) when improving on the nested-loop solution is important?

  1. A

    It reverses the array and checks whether the first and last values match.

  2. B

    It sorts the array and returns true only if every value is unique.

  3. C

    It records previously visited values and returns true when a value is encountered again.

  4. D

    It uses binary search on the original array without sorting it.

13
True or false
1 point

True or false: Choosing a dynamic list eliminates the need to consider the cost of shifting later elements when inserting or removing in the middle.

  1. A

    True

  2. B

    False

14
Open ended
1 point

You are designing a program that stores a sequence of values. Explain when you would choose an array instead of a dynamic list, and when you would choose a dynamic list instead. Include the performance or usage trade-offs that support your decision.

15
Choose one
1 point

An array has a length of 5. Which range contains all of its valid zero-based indexes?

  1. A

    0 through 5

  2. B

    0 through 4

  3. C

    1 through 5

  4. D

    1 through 4

16
Choose one
1 point

Given the array [12, 7, 9, 4], a program executes values[1] = 15. What is the resulting array?

  1. A

    [12, 7, 9]

  2. B

    [12, 7, 9, 4, 0]

  3. C

    [12, 15, 9, 4]

  4. D

    [15, 7, 9, 4]

17
Choose one
1 point

What does linearSearch([14, 7, 22, 9], 11) return when the function returns the first matching index and returns -1 if the target is absent?

  1. A

    0

  2. B

    1

  3. C

    2

  4. D

    -1

18
Choose one
1 point

A program is about to use binary search on an array. Which condition is essential for the search to provide valid results?

  1. A

    The array must be sorted according to the search ordering.

  2. B

    The array must contain only distinct values.

  3. C

    The array must have an even length.

  4. D

    The target must be located at an endpoint.

19
Written response
1 point

In a zero-based array, what index contains the element at human-readable position 3?

20
Written response
1 point

What is the time complexity of traversing an array with n elements once, visiting each element approximately one time?