Free Online Flashcard Deck

02 Arrays and Dynamic Arrays Free Online FlashCards

Study 02 Arrays and Dynamic Arrays with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.

12 cards
01
Front

What is the valid index range of a zero-based array of length nn?

Back

The first element is at index 00, and the last element of an array of length nn is at index n−1n-1.

02
Front

How is an array element’s address calculated?

Back

address⁡(A[i])=B+i×w\operatorname{address}(A[i]) = B + i \times w, where BB is the base address and ww is the element size in bytes.

03
Front

What is the typical time complexity of indexed array access?

Back

Accessing or updating an element by a known index is typically O(1)O(1) because its address can be calculated directly.

04
Front

How does an array index differ from an array value?

Back

An index identifies a position; a value is the data stored at that position. For example, 2929 is the value at index 22.

05
Front

What is the time complexity of traversing an array?

Back

Traversing an array of nn elements takes O(n)O(n) time because each element is visited.

06
Front

What happens to existing elements during array insertion?

Back

Insertion at index ii shifts every existing element from index ii onward one position to the right.

07
Front

Why does array insertion shift elements from right to left?

Back

The loop moves elements from right to left so each value is copied before its destination can overwrite it.

08
Front

How does array deletion close the removed element’s gap?

Back

Deletion shifts later elements one position left to close the gap left by the removed element.

09
Front

Why are middle insertions and deletions usually O(n)O(n)?

Back

Insertion or deletion at the beginning or middle usually takes O(n)O(n) time because elements must be shifted.

10
Front

What is the difference between dynamic-array size and capacity?

Back

Size is the number of elements currently stored; capacity is the number of elements the allocated storage can hold.

11
Front

What happens when a dynamic array becomes full?

Back

It allocates a larger backing array, copies the existing elements, replaces the old backing array, and inserts the new element.

12
Front

What is the amortized complexity of appending to a dynamic array?

Back

With geometric capacity growth, appending is O(1)O(1) amortized, although an individual resize can take O(n)O(n) time.