Practice question · Select all that apply
A program uses a List ADT. Its array implementation is replaced by a linked one, and every published operation still behaves as documented. Select every statement that remains true afterwards.
Hints
- The swap changes the implementation and nothing about the interface.
- One option would mean the two structures were not implementations of the same ADT at all.
Show the answer
- A. get, add, remove and size behave as before
- B. get(i) may take substantially longer
- C. Code assuming contiguous storage may break
- E. The memory layout of the elements has changed
Why
Behaviour is preserved but performance and layout are not, that is the entire trade being made. The one false statement is that the operations mean something different: if they did, the swap would not be legal. Code that reached past the interface to assume contiguity was never protected, and it is exactly such code that breaks.
Practise Abstract Data Types and Interfaces
The app has 6 more questions on this lesson, and keeps your place in the course. Computer Science I is free to start.
More questions on Abstract Data Types and Interfaces
- A List ADT is being documented. Sort each statement by whether it belongs to the interface or describes one…
- A program uses a List ADT backed by an array. The implementation is swapped for a linked one and not a single…
- A team swaps a List implementation from array-backed to linked, changes no calling code, and the nightly…
- Documenting a List ADT by writing down the array implementation's exact timings makes the documentation more…