Computer Science I / Abstract Data Types and Interfaces
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
  1. The ADT promises the caller a set of operations. Ask what it says about how long each takes.
  2. 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.

Read the lesson: Abstract Data Types and Interfaces →

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