Free Practice Quiz Question List

3 Arrays and Dynamic Arrays Online Quiz Questions

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

20 questions
01
True or false
1 point

True or false: Because an array stores same-sized elements in contiguous memory, accessing an element by index can take O(1)O(1) time.

  1. A

    True

  2. B

    False

02
Choose one
1 point

Given values = [18, 7, 25, 4], what value does values[2] return?

  1. A

    18

  2. B

    25

  3. C

    7

  4. D

    4

03
Written response
1 point

An array has length 8 and uses zero-based indexing. What is the index of its final element?

04
Fill in the blank
1 point

A traversal that visits every element of an array containing nn elements takes time.

05
Choose one
1 point

Why can inserting an element at the beginning of an array take O(n)O(n) time?

  1. A

    No elements need to move, so insertion is always O(1)O(1).

  2. B

    Existing elements must shift right, so insertion can take O(n)O(n).

  3. C

    The array must be searched, so insertion is always O(log⁡n)O(\log n).

  4. D

    Only the new element is copied, so insertion is always O(1)O(1).

06
True or false
1 point

True or false: If order must be maintained, deleting the last element of an array takes O(1)O(1) time.

  1. A

    True

  2. B

    False

07
Choose all
1 point

Select all properties that correctly describe a dynamic array.

  1. A

    It tracks the number of stored elements as size.

  2. B

    It tracks the number of available positions in its backing array as capacity.

  3. C

    Insertion at the beginning is always O(1)O(1).

  4. D

    Indexed access is O(1)O(1).

08
Written response
1 point

A dynamic array has size 3 and capacity 5. How many additional elements can it store before resizing?

09
Fill in the blank
1 point

In a typical dynamic-array append, when size equals capacity, the structure must first the backing array.

10
Choose one
1 point

Why does geometric capacity growth make repeated dynamic-array appends have amortized cost O(1)O(1)?

  1. A

    Every individual append, including a resize, takes O(1)O(1).

  2. B

    Geometric growth prevents any copying during a resize.

  3. C

    The total number of copied elements across many appends is O(n)O(n).

  4. D

    A dynamic array never allocates a new backing array.

11
Choose all
1 point

Select all situations for which a dynamic array is generally a strong choice.

  1. A

    Fast indexed access is a strength.

  2. B

    Efficient traversal is a strength.

  3. C

    Frequent insertion at the beginning is a strength because no shifting is needed.

  4. D

    Appending near the end is a strength.

12
Open ended
1 point

Explain what happens when a dynamic array is full and an append triggers resizing. Include the major resizing steps and explain why geometric growth gives append an amortized complexity of O(1)O(1), even though one resize can take O(n)O(n).

13
Choose one
1 point

Which capacity-reservation strategy best follows the material's practical guidance when future growth can be estimated?

  1. A

    Reserve exactly one additional position before every append.

  2. B

    Reserve capacity in meaningful batches when future growth is known or can be estimated.

  3. C

    Never reserve capacity because reservation always changes the logical size.

  4. D

    Reserve only after every append has already triggered a resize.

14
True or false
1 point

True or false: Shrinking a dynamic array after every deletion is a good way to avoid thrashing.

  1. A

    True

  2. B

    False

15
Choose one
1 point

An array has length 6. Which range contains all of its valid zero-based indices?

  1. A

    0 through 6

  2. B

    0 through 5

  3. C

    1 through 6

  4. D

    1 through 5

16
Choose one
1 point

Why can an array access by index usually run in O(1)O(1) time?

  1. A

    The address is computed from the base address, index, and element size.

  2. B

    The array is searched from the first element until the requested one is found.

  3. C

    Every element is copied before the requested element is accessed.

  4. D

    The requested element is always stored at the same physical address for every array.

17
Choose one
1 point

A program visits every element of an array once and creates no additional structure proportional to the array length. What are the time and auxiliary-space complexities?

  1. A

    Time O(1)O(1), auxiliary space O(1)O(1)

  2. B

    Time O(1)O(1), auxiliary space O(n)O(n)

  3. C

    Time O(n)O(n), auxiliary space O(1)O(1)

  4. D

    Time O(n)O(n), auxiliary space O(n)O(n)

18
Choose one
1 point

To insert an element at an index in the middle of an ordered array, what must the implementation generally do?

  1. A

    Only the new element is written, so insertion is always O(1)O(1).

  2. B

    The array is converted into a linked structure before insertion.

  3. C

    Elements before the insertion point are shifted right.

  4. D

    Elements from the end down to the insertion point are shifted right.

19
Written response
1 point

A dynamic array has size 7 and capacity 8. After one successful append, what is its resulting size?

20
Written response
1 point

An unordered array contains n elements. To delete the element at index i in O(1) time when preserving the order of the remaining elements is unnecessary, which existing element should replace array[i] before the logical size is reduced?