Which structure fits an append-heavy list with frequent indexed reads?
Instruction: A service appends records to a list and frequently reads a record by its numeric position. Arbitrary deletion is rare. Compare a dynamic array with singly and doubly linked lists, including traversal, deletion prerequisites, capacity and per-node memory costs.
Updated
Official answer
The access pattern favors a resizable array unless there is a stronger measured constraint. Appending can be amortized O(1), and selecting the item at an index is O(1). A linked list must traverse to a randomly chosen index, costing O(n) in the worst case.
A doubly linked list can remove a known node in O(1) by changing neighboring links. That advantage does not include finding the node. In a singly linked list, ordinary deletion also needs the predecessor or a suitable special case; having only a tail node is insufficient for general constant-time deletion.
Linked nodes use memory for links, allocation metadata and sometimes padding. Dynamic arrays may reserve unused capacity, but linked lists do not have “no memory wastage.” Exact overhead depends on representation and runtime.
If the requirement changes to frequent insertion/removal at an already-positioned cursor, reconsider a linked structure. For the stated append-and-index workload, start with the dynamic array and measure realistic sizes and allocation behavior.