A data structure decides which operations are cheap and which are expensive. .NET already supplies the common choices through types such as List<T>, Dictionary<TKey, TValue>, HashSet<T>, Queue<T>, and PriorityQueue<TElement, TPriority>. Collection choice usually changes performance more than tuning the loop around a poor choice.

The workload picks the structure. Positional access points to an array or List<T>. Key lookup points to Dictionary<TKey, TValue>, membership to HashSet<T>, and FIFO work to Queue<T>. Ordered traversal may need a SortedSet<T> or a sorted array, depending on how often the data changes. A repeated linear scan over a List<T> is usually a representation problem, not a slow implementation of List<T>.

Choose by Workload and Access Pattern

Start from the operation that dominates the workload, then account for ordering, memory layout, and concurrency. A structure with the right asymptotic lookup can still lose when it adds indirection to a small, scan-heavy collection.

WorkloadDefault structureWhat it buysCost or boundary
Dense positional access and iterationArray or List<T>O(1) indexing and contiguous storageMiddle insertions shift elements
Key-to-value lookupDictionary<TKey, TValue>Expected O(1) lookup by a stable keyHashing, resizing, and no sorted traversal
Membership and set algebraHashSet<T>Expected O(1) containment. Linear-time set algebra over the participating inputsStores no associated value or order. Collision patterns affect worst-case lookup cost
FIFO workQueue<T> or Channel<T>Preserves arrival order. A bounded channel in Wait mode adds asynchronous coordination and backpressureUnbounded channels do not apply backpressure. Bounded drop modes discard or replace items instead of waiting
Repeated minimum or maximum selectionPriorityQueue<TElement, TPriority>O(1) peek and O(log n) enqueue/dequeueIteration is not globally sorted
Ordered range queriesSorted array or balanced treeBinary search or ordered traversalUpdates are expensive in arrays. Trees add pointer overhead
Prefix lookupTrieWork scales with key length rather than entry countHigh node and reference overhead
Relationships and pathsGraph adjacency listStores sparse edges without an n × n matrixTraversal needs visited-state and cycle handling
Adaptive spatial range or nearest-neighbor queriesQuadtree, R-tree, or spatial database indexPrunes regions that cannot intersect the queryChoice depends on data distribution and persistence model
Spatial candidates on a one-dimensional indexGeohashTurns fixed-grid cells into sortable prefixesAdjacent points can cross a prefix boundary. Exact filtering is still required
Cheap negative membership testsBloom filterAvoids expensive downstream lookups with compact stateFalse positives are possible. Deletions need a variant

computer science data structures

The visual is an example inventory, not a selector. The table above is authoritative because the same structure can be right or wrong depending on the dominant operation and storage boundary.

References

6 items under this folder.