Practice question · Multiple choice
A program uses a List ADT backed by an array. The implementation is swapped for a linked one and not a single line of calling code changes - yet the program becomes noticeably slower. How can both facts be true at once?
Hints
- The ADT promises the caller a set of operations. Ask what it says about how long each takes.
- What does
list[500]cost in an array, and what does it cost in a chain of nodes?
Show the answer
D. Because the interface guarantees operations, not costs.
Why
An ADT is a contract about behaviour, what operations exist and what they return, and cost is not in it, which is exactly why the swap compiles and why it can wreck performance. Indexing is the clearest case: list[500] is one multiplication and a read in an array, and five hundred pointer follows in a linked list. Neither structure dominates, which is why the choice is a design decision.
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. Its array implementation is replaced by a linked one, and every published…
- 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…