Free Practice Quiz Question List

02 Arrays and Dynamic Arrays Online Quiz Questions

Use this free practice quiz with 20 questions to review 02 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: In a zero-based array with length n, the largest valid index is n − 1.

  1. A

    True

  2. B

    False

02
Choose one
1 point

Why does reading an array element by a known index typically take O(1)O(1) time?

  1. A

    It must examine every earlier element in the array.

  2. B

    It calculates the element address from the base address, index, and element width.

  3. C

    It shifts all later elements before reading the requested element.

  4. D

    It copies the entire array into a temporary array.

03
Choose one
1 point

An array contains [10, 20, 30, 40]. If 25 is inserted at index 2 while preserving the existing order, what is the resulting array?

  1. A

    [25, 10, 20, 30, 40]

  2. B

    [10, 25, 20, 30, 40]

  3. C

    [10, 20, 25, 30, 40]

  4. D

    [10, 20, 30, 25, 40]

04
Written response
1 point

A rectangular matrix has 3 columns. Using zero-based row-major storage, what flat-array index corresponds to row 1, column 2?

05
Fill in the blank
1 point

Complete the statement: A traversal that visits every element of an array of length nn takes time.

06
Choose all
1 point

Which two statements correctly describe a dynamic array? Select all that apply.

  1. A

    It maintains a logical size that can differ from capacity.

  2. B

    It can never reallocate its backing storage.

  3. C

    It can allocate a larger backing array when it becomes full.

  4. D

    It requires every element to be stored at a different memory address from all other elements.

07
True or false
1 point

True or false: A single append to a dynamic array can take O(n)O(n) time if resizing and copying are required.

  1. A

    True

  2. B

    False

08
Written response
1 point

What is the amortized time complexity of appending to a dynamic array when its capacity grows geometrically? Give the complexity as O(1)O(1) and include the word amortized.

09
Choose one
1 point

An array contains [10, 20, 30, 40]. If the element at index 1 is deleted and the gap is closed, what is the resulting array?

  1. A

    [10, 20, 40]

  2. B

    [10, 30, 40]

  3. C

    [20, 30, 40]

  4. D

    [10, 30, 20, 40]

10
Choose all
1 point

Which two workload characteristics support choosing an array-based structure, particularly a dynamic array? Select all that apply.

  1. A

    Fast access by position is important.

  2. B

    Appending is more common than inserting near the beginning or middle.

  3. C

    Frequent middle insertion must avoid shifting existing elements.

  4. D

    The number of elements is guaranteed to remain fixed, but indexed access is unnecessary.

11
Fill in the blank
1 point

Complete both statements about inserting into an array: To avoid overwriting values, the shift loop proceeds from . Inserting in the middle takes time in the worst case.

12
Open ended
1 point

Explain why appending to a dynamically growing array is O(1)O(1) amortized even though an individual append can take O(n)O(n) time. Include what happens when the backing array is full.

13
True or false
1 point

True or false: In a row-major flat representation with 3 columns, the element at zero-based row 1 and column 2 has flat index 5.

  1. A

    True

  2. B

    False

14
Choose one
1 point

Which situation most strongly favors a fixed-length array rather than a dynamic array?

  1. A

    A collection grows unpredictably and needs frequent appends.

  2. B

    The program stores exactly seven weekday values and the number of values will not change.

  3. C

    The program frequently inserts records near the beginning.

  4. D

    The program needs a collection whose size changes often.

15
Choose one
1 point

An array has length 5 and uses zero-based indexing. Which index contains its last element?

  1. A

    3

  2. B

    4

  3. C

    5

  4. D

    6

16
Choose one
1 point

An array starts at address B=1000B=1000, each element occupies w=4w=4 bytes, and you access index i=3i=3. What address does the formula B+i×wB+i\times w produce?

  1. A

    1008

  2. B

    1012

  3. C

    1016

  4. D

    1024

17
Choose one
1 point

Starting with [10, 20, 30, 40], which array results from inserting 25 at index 2 while preserving the order of the existing elements?

  1. A

    [25, 10, 20, 30, 40]

  2. B

    [10, 25, 20, 30, 40]

  3. C

    [10, 20, 25, 30, 40]

  4. D

    [10, 20, 30, 25, 40]

18
Choose one
1 point

A dynamic array is full when an append is requested. What is the worst-case time for that individual append?

  1. A

    It is always O(1)O(1).

  2. B

    It is always O(log⁡n)O(\log n).

  3. C

    It can be O(n)O(n) when resizing is required.

  4. D

    It is always O(n2)O(n^2).

19
Written response
1 point

A rectangular matrix has 5 rows and 6 columns. How many elements does a complete nested-loop traversal process?

20
Written response
1 point

An array contains nn elements, but the position of a target value is unknown. An algorithm checks the elements one at a time until it finds the target or reaches the end. What is the worst-case asymptotic time complexity of this search?