Free Online Flashcard Deck

3 Arrays and Dynamic Arrays Free Online FlashCards

Study 3 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 an array?

Back

An array is a collection of elements stored in a fixed-size, ordered sequence.

02
Front

What indices are valid in an array of length nn?

Back

For an array of length nn, valid indices are 0,1,2,…,n−10, 1, 2, \ldots, n-1.

03
Front

How is an array element's address calculated?

Back
address(array[i])=base_address+i×element_size\mathrm{address}(\mathrm{array}[i])=\mathrm{base\_address}+i\times\mathrm{element\_size}
04
Front

Why is indexed array access O(1)O(1)?

Back

Accessing or replacing an element by index takes O(1)O(1) time because its address is calculated directly.

05
Front

What are traversal's time and auxiliary-space costs?

Back

Traversal visits every element, so it takes O(n)O(n) time and O(1)O(1) auxiliary space when no proportional extra structure is created.

06
Front

What are linear search's best- and worst-case times?

Back

Linear search takes O(1)O(1) time in the best case and O(n)O(n) time in the worst case.

07
Front

Why is middle insertion in an array O(n)O(n)?

Back

Insertion at the beginning or middle is O(n)O(n) because elements must be shifted right to preserve order.

08
Front

How does deletion position affect array complexity?

Back

Deleting the last element is O(1)O(1), while deleting from the beginning or middle is usually O(n)O(n) because later elements shift left.

09
Front

How can unordered deletion from an array be made O(1)O(1)?

Back

If order is unnecessary, replace the deleted element with the last element and reduce the length; this makes deletion O(1)O(1).

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 backing array can hold.

11
Front

What happens when a dynamic array is full during append?

Back

When full, a dynamic array allocates a larger backing array and copies or moves the existing elements, so that append costs O(n)O(n) for that operation.

12
Front

Why does geometric growth give amortized O(1)O(1) append?

Back

Geometric growth, such as doubling capacity, makes repeated appends O(1)O(1) amortized even though an individual resize costs O(n)O(n).