Data Structures

Chapter 14
Data-Structure Selection and Technology Decision-Making

Bachelors Program in IT
Data Structures   •   Bachelor

Data-Structure Selection and Technology Decision-Making

Introduction

Selecting a data structure is not merely a programming exercise. In enterprise systems, the choice of an array, hash table, tree, graph, queue, or specialized index can influence latency, cloud expenditure, reliability, security, maintainability, and the ability of an organization to change its products. A technically fast structure may be unsuitable if it is difficult to operate, consumes excessive memory, creates unacceptable consistency risks, or locks an organization into a vendor-specific technology.

Data-structure selection is therefore a technology decision. It connects algorithmic analysis with workload analysis, benchmarking, architecture, governance, and business priorities. The central question is not “Which structure is fastest?” but “Which structure provides an acceptable balance of performance, scalability, correctness, cost, operational simplicity, and future adaptability for this workload?”

Learning Objectives

By the end of this chapter, students should be able to:

  1. Characterize workloads using operations, data volume, concurrency, locality, and service-level objectives.
  2. Relate data-structure properties to time complexity, space complexity, and scalability.
  3. Design meaningful benchmarks and interpret their results cautiously.
  4. Evaluate trade-offs involving performance, maintainability, cost, risk, and governance.
  5. Select suitable structures for enterprise and digital-transformation scenarios.
  6. Communicate a defensible technology recommendation to technical and non-technical stakeholders.

1. The Decision Context

A data structure organizes data so that required operations can be performed efficiently. Common structures include arrays, linked lists, stacks, queues, hash tables, heaps, balanced search trees, tries, and graphs. In practice, these structures appear inside programming-language libraries, databases, caches, message brokers, search engines, and distributed platforms.

A decision begins with a workload rather than with a favorite technology. A workload description should include:

  • Operations: lookup, insertion, deletion, update, traversal, range query, sorting, aggregation, or shortest-path computation.
  • Frequency: the proportion or number of each operation over a defined period.
  • Data size: number of records, object size, key size, and expected growth.
  • Access pattern: sequential, random, temporal, spatial, prefix-based, or range-based access.
  • Concurrency: number of simultaneous readers and writers and the required isolation behavior.
  • Service objectives: latency, throughput, availability, durability, and recovery targets.
  • Change profile: how often the schema, algorithms, or access patterns are expected to evolve.

For example, a read-dominant directory with exact-key lookups suggests a hash table or key-value index. A system requiring ordered iteration and range queries suggests a balanced search tree or a database index based on a tree. A task scheduler requires priority operations, making a heap a natural candidate. A social-network recommendation service requires graph representations and graph algorithms rather than a simple list.

2. From Requirements to Workload Model

A workload model converts informal requirements into measurable assumptions. Suppose a service receives 10,000 requests per second, of which 80% are exact lookups, 15% are updates, and 5% are range queries. A candidate that excels at exact lookup but performs poorly on range queries may still be unsuitable if the range queries have strict latency requirements.

A simple operation mix can be represented by the weighted average cost:

Cavg = ∑(i=1 to n) pi Ci

Here, Cavg is the estimated average cost per operation, pi is the proportion of operation type i, and Ci is the cost of that operation. The assumptions are that the operation proportions are known or estimated, the costs are measured under comparable conditions, and interactions among operations do not materially change the result. The unit of Cavg must match the unit of Ci, such as microseconds per operation.

This average can hide important behavior. If a service agreement requires 99% of requests to complete within 50 ms, average latency is insufficient. Percentiles are more appropriate. The 99th percentile, written p99, is the latency value below which 99% of observations fall. A structure that has a low average but severe pauses or contention may violate the service objective.

Capacity must also be considered. If each request requires c CPU-seconds of work and the arrival rate is λ requests per second, approximate CPU utilization is:

U = λc

The formula assumes a single normalized CPU capacity of one CPU-second per second. For m equivalent CPUs, a simplified utilization estimate is U = λc/m. Real systems also include I/O waits, synchronization, garbage collection, network overhead, and scheduling effects, so this is an estimation model rather than a complete performance law. Sustainable operation normally requires utilization below capacity with headroom for bursts and failures.

3. Complexity as a First Filter

Asymptotic complexity describes how resource requirements grow as input size n increases. It is valuable because it exposes scalability risks before implementation. Typical classifications include:

Structure or operationTypical time complexityImportant qualification
Array indexingO(1)Requires a known valid index
Unsorted-array searchO(n)May stop early for a successful search
Hash-table lookupExpected O(1)Depends on hashing and load factor; worst case can be O(n)
Balanced search-tree lookupO(log n)Assumes the tree remains balanced
Binary heap insertion/removalO(log n)Access to the extreme priority is O(1)
Linked-list insertion at a known nodeO(1)Finding the node may cost O(n)
Graph traversalO(V + E)Adjacency-list representation; V vertices and E edges

Big-O notation suppresses constants and lower-order terms. Consequently, an O(log n) algorithm is not automatically faster than an O(1) algorithm for small data sets. Memory layout, cache locality, allocation overhead, key size, concurrency, and implementation quality can dominate in real workloads.

Complexity also requires qualifications. Hash-table performance depends on the load factor:

α = n / m

where n is the number of stored entries and m is the number of buckets. As α grows, collisions generally increase. A hash table must use a collision strategy, such as chaining or open addressing, and must resize or otherwise manage capacity. Claims of constant-time lookup therefore mean expected or amortized behavior under suitable assumptions, not an unconditional guarantee.

Space complexity includes auxiliary memory, metadata, pointers, buckets, indexes, and temporary structures. A linked structure may have linear space complexity like an array but use substantially more bytes per element because of links and object headers. In a memory-constrained environment, this difference can be more important than a small difference in operation count.

4. Matching Structures to Access Patterns

Arrays and dynamic arrays

Arrays provide contiguous storage and efficient indexing. They are often excellent for read-heavy workloads, numerical data, batching, and cache-friendly scans. Inserting at the end of a dynamic array is usually amortized O(1), although resizing occasionally requires O(n) copying. Inserting at the beginning or middle generally requires shifting elements and costs O(n).

Linked lists

Linked lists support insertion or removal at a known position without shifting subsequent elements. However, locating that position is usually linear, and pointer chasing can cause poor cache locality. They are therefore less universally useful than introductory examples suggest. A linked list is justified when frequent local splicing is central and the system already has efficient references to nodes.

Hash tables

Hash tables suit exact-key lookup, insertion, and deletion. They are common in caches, symbol tables, session stores, and indexes. They do not naturally support sorted traversal or efficient range queries. Security-sensitive systems must also consider adversarial inputs that deliberately cause collisions; robust hash functions, randomized seeding, rate limits, or alternative structures may be required.

Balanced search trees

Balanced trees, including AVL trees and red-black trees, provide ordered operations with logarithmic worst-case behavior. They support predecessor, successor, sorted iteration, and range queries. Their pointer-rich representation can be slower than a hash table for exact lookup, but their predictable bounds and ordering are valuable.

Heaps and priority queues

A heap efficiently identifies the minimum or maximum priority item. It is appropriate for schedulers, event simulation, graph algorithms, and top-k processing. It is not a general-purpose structure for arbitrary search: locating an unrelated element is not its strength.

Tries and prefix structures

Tries organize strings by prefixes. They support autocomplete, routing tables, and lexical lookup, but memory consumption can be substantial. Compressed tries reduce wasted nodes at the cost of implementation complexity.

Graph representations

An adjacency matrix uses approximately O(V2) space and supports constant-time edge existence checks, making it suitable for dense graphs. An adjacency list uses O(V + E) space and is usually preferable for sparse graphs. The correct representation depends on graph density, traversal frequency, edge attributes, and update patterns.

5. Benchmarking: Evidence Rather Than Demonstration

A benchmark is an experiment designed to measure a system under specified conditions. It should answer a decision question, such as whether a hash index meets p99 latency at the projected load, not merely demonstrate that code runs.

A credible benchmark includes:

  1. A representative dataset: realistic key distributions, record sizes, duplicates, and hot or cold items.
  2. A defined operation mix: measured frequencies rather than arbitrary test loops.
  3. Warm-up and steady-state phases: especially for managed runtimes, caches, just-in-time compilation, and storage systems.
  4. Controlled environment: documented processor, memory, operating system, runtime, compiler, and configuration.
  5. Repeated trials: reporting median, tail percentiles, variation, and confidence or uncertainty where appropriate.
  6. Resource measurements: CPU, memory, allocation rate, garbage collection, I/O, network traffic, and power where relevant.
  7. Scaling tests: multiple data sizes and concurrency levels, not one convenient input.

A throughput measurement can be expressed as:

T = N / Δt

where T is throughput in operations per second, N is the number of completed operations, and Δt is elapsed time in seconds. The measurement is meaningful only if operations are correctly completed, the workload is specified, and setup time is treated consistently.

Benchmark results should not be generalized beyond their conditions. A microbenchmark may show that one map implementation is faster on a particular processor, but it cannot alone establish lower cloud cost, better failure behavior, or maintainability. Benchmark-driven development also risks optimizing an unimportant operation. Workload analysis must precede measurement.

6. A Multi-Criteria Decision Framework

Enterprise selection should evaluate several dimensions simultaneously. A useful framework is to identify mandatory constraints first and then score viable alternatives.

CriterionQuestions to ask
CorrectnessDoes the structure preserve required ordering, uniqueness, atomicity, and consistency?
PerformanceWhat are expected and worst-case time and space costs?
ScalabilityHow does it behave as data, traffic, and concurrency grow?
ReliabilityWhat happens during failure, restart, corruption, or partial deployment?
MaintainabilityCan ordinary developers understand, test, and modify it?
OperabilityCan it be monitored, backed up, upgraded, and diagnosed?
CostWhat are memory, compute, storage, licensing, and labor costs?
SecurityCan malformed or adversarial inputs degrade performance or expose data?
PortabilityDoes the decision create dependence on a platform or vendor?
GovernanceCan retention, privacy, audit, and access requirements be enforced?

A weighted score can make assumptions visible:

Sj = ∑(i=1 to k) wi rij

Sj is the score for candidate j, wi is the weight of criterion i, and rij is candidate j’s rating on criterion i. Weights should be non-negative and normally sum to 1; ratings must use a documented scale. A weighted score does not replace judgment. A candidate that violates a mandatory security or latency constraint should be rejected regardless of its total score.

The total cost of ownership includes more than purchase price. A conceptual model is:

TCO = Cdev + Crun + Cops + Cchange + Crisk

The terms represent development, runtime infrastructure, operations, future change, and expected risk costs. These are not always precisely measurable. The model is useful because it prevents a team from comparing only benchmark speed while ignoring staff training, incident response, migration, and vendor dependence.

7. Scalability and Architecture Trade-offs

Scaling can be vertical, by providing more resources to one node, or horizontal, by distributing work across nodes. In-memory structures such as local hash tables offer low latency but complicate replication, failover, and consistency. Distributed structures improve capacity and availability but add network latency, serialization, partitioning, coordination, and operational complexity.

A structure’s theoretical complexity may remain favorable while distributed behavior becomes expensive. A local tree lookup may require a few memory accesses; a distributed lookup may require a network round trip and a remote replica decision. Consequently, architecture must distinguish algorithmic cost from system cost.

Caching illustrates a common trade-off. A cache can reduce database work and latency, but it introduces stale data, invalidation complexity, memory cost, and possible cache stampedes. A cache should be justified by measured locality and a defined freshness policy. “Add a cache” is not a substitute for understanding the workload.

Digital transformation projects frequently replace legacy files or relational tables with document stores, key-value systems, search indexes, or graph databases. The choice should follow access patterns and consistency requirements. Migrating technology without changing the workload, data model, governance, or operating model may produce little benefit and substantial risk.

8. Maintainability, Risk, and Governance

Maintainability is a performance characteristic of the organization. A sophisticated custom index may reduce latency but increase onboarding time, defect probability, testing effort, and dependence on a small number of specialists. Standard library structures and mature managed services often have lower organizational risk even when they are not theoretically optimal.

Risk analysis should identify:

  • failure modes and their consequences;
  • assumptions that could become false as demand changes;
  • dependencies on libraries, vendors, or specialized staff;
  • migration and rollback strategies;
  • observability gaps;
  • security and privacy exposures; and
  • regulatory obligations concerning retention, access, explainability, and deletion.

Data structures can affect privacy. An index, cache, log, or search structure may create additional copies of personal data. Deletion must therefore remove or appropriately expire derived data, not only the primary record. Access-control metadata must be indexed and enforced consistently. Sensitive keys should not be exposed through predictable identifiers or unprotected diagnostic output.

AI systems make these issues more complex. Vector indexes support semantic retrieval, but approximate-nearest-neighbor methods trade exactness for speed and memory. Evaluation must measure retrieval quality, latency, update freshness, bias, and exposure of confidential information. A vector index should not be selected merely because it is fashionable; the organization must define what “similarity” means and how errors affect decisions.

9. A Practical Selection Process

A defensible process has the following stages:

  1. State the decision: define the business capability and the alternatives.
  2. Capture constraints: record latency, throughput, availability, durability, compliance, budget, and delivery deadlines.
  3. Model the workload: quantify operations, sizes, growth, concurrency, locality, and bursts.
  4. Shortlist structures: eliminate candidates that cannot satisfy mandatory requirements.
  5. Analyze complexity: document expected and worst-case time and space behavior.
  6. Build a representative prototype: include realistic serialization, persistence, concurrency, and failure behavior.
  7. Benchmark and validate: measure throughput, percentiles, resource use, and scaling.
  8. Assess total cost and risk: include development, operations, change, and exit costs.
  9. Run a pilot: deploy in a limited environment with monitoring and rollback.
  10. Document the decision: record assumptions, evidence, rejected alternatives, and review triggers.

The result should be an architecture decision record. It should state not only what was selected, but why, under which assumptions, and when the decision must be revisited.

10. Illustrative Case: Retail Inventory Availability Service

Background

A fictional national retailer is modernizing its inventory platform. Store and warehouse systems produce 40 million inventory records. Online customers need exact SKU-and-location availability, while planners require sorted reports and range queries by product category and quantity.

Problem

The legacy service stores records in an unsorted in-memory list and scans the list for each request. The current average response time is acceptable during quiet periods, but peak traffic causes high CPU use and unacceptable p99 latency. The organization expects records to double within three years.

Analysis

The workload is approximately 85% exact lookups, 10% updates, and 5% range queries. Exact lookup requires a composite key consisting of SKU and location. A hash table is attractive for the dominant lookup operation. However, it does not efficiently provide ordered category reports. A balanced tree or database index supports ordering and ranges but may be slower for exact lookups. Memory limits also matter: storing every record in multiple large structures may exceed the service budget.

The team identifies three options:

  • retain the list and optimize code;
  • use a hash index for exact availability and a separate persistent ordered index for reporting; or
  • use one ordered structure for all operations.

The first option has linear lookup behavior and does not scale with projected growth. The third simplifies the number of structures but may impose unnecessary cost on the dominant exact-lookup path. The second introduces synchronization and consistency responsibilities, but those can be managed through a single authoritative update stream and reconciliation checks.

Approach and Solution

The team prototypes the second option using realistic keys, skewed traffic, concurrent updates, restart tests, and failure injection. The hash index is partitioned to reduce lock contention. Reports read from the ordered persistent index, whose freshness objective is explicitly set at two minutes. Online availability reads use the hash index and require current data.

The architecture decision includes a rebuild procedure, checksum-based reconciliation, monitoring for index lag, memory thresholds, and a rollback path to the legacy service. The team rejects a custom hash implementation in favor of a mature library because the expected performance is sufficient and the library has stronger testing and security maintenance.

Outcome

The new design meets the online latency objective in the pilot and scales more predictably as records increase. Reporting becomes slightly delayed but remains within the stated business tolerance. Operational complexity increases because two representations must be monitored. The decision is therefore conditional: if reporting becomes real-time, the architecture must be reassessed.

Learning Points

The case demonstrates that selection follows workload segmentation. It also shows why correctness and freshness requirements must be stated separately, why a benchmark must include realistic concurrency and skew, and why a multi-structure design can be appropriate when each representation has a clear responsibility.

Challenges and Limitations

No framework eliminates uncertainty. Workloads change, benchmarks contain measurement error, and business priorities can conflict. Weighted scoring can create false precision when ratings are subjective. Complexity analysis ignores constants and hardware behavior. Prototypes may omit operational failures. Vendor documentation may report favorable benchmarks under nonrepresentative conditions.

A further limitation is organizational: teams may select familiar tools to reduce immediate delivery risk, even when long-term costs are higher. Conversely, architecture groups may over-engineer a system in pursuit of theoretical scalability. The appropriate response is not to seek a universally best structure but to make assumptions explicit, measure material risks, and create review points.

Best Practices

  • Start with operations and service objectives, not product names.
  • Separate mandatory constraints from preferences.
  • Document expected and worst-case behavior.
  • Measure tail latency, not only averages.
  • Test realistic data distributions and growth levels.
  • Include memory, allocation, synchronization, and network costs.
  • Prefer mature, well-supported implementations unless custom behavior is essential.
  • Treat indexes and caches as maintained data, with ownership and recovery procedures.
  • Consider security, privacy, compliance, and deletion requirements from the beginning.
  • Record assumptions and define triggers for revisiting the decision.
  • Communicate trade-offs in business terms as well as technical terms.

Chapter Summary

Data-structure selection is a strategic engineering activity that connects workload analysis with architecture and organizational objectives. Arrays provide efficient indexed access and locality; hash tables support expected constant-time exact-key operations; balanced trees provide ordered and range operations; heaps support priority processing; tries support prefix queries; and graph representations must be selected according to graph density and traversal needs.

Asymptotic complexity is a valuable first filter, but real decisions also depend on constants, memory layout, concurrency, distribution, failure behavior, and operational cost. Benchmarks must use representative workloads, controlled environments, warm-up, repeated trials, percentile latency, and resource measurements. A multi-criteria framework helps compare performance, scalability, maintainability, cost, risk, security, governance, and portability.

Enterprise decisions should identify mandatory constraints, prototype realistic alternatives, evaluate total cost of ownership, conduct pilots, and document assumptions in an architecture decision record. The best choice is not necessarily the fastest structure; it is the option that satisfies required correctness and service objectives while remaining affordable, understandable, secure, operable, and adaptable.

Key Terms

Workload model: A quantified description of operations, data, traffic, access patterns, and constraints.

Asymptotic complexity: A description of how resource requirements grow as input size increases.

Big-O notation: Notation for an upper-growth classification that suppresses constants and lower-order terms.

Load factor: The ratio of stored entries to buckets in a hash table.

Hash table: A structure that maps keys to values using a hash function.

Balanced search tree: An ordered tree designed to maintain logarithmic height.

Heap: A structure that maintains a minimum or maximum priority at its root.

Trie: A prefix-oriented tree for strings or sequences.

Adjacency list: A graph representation storing the neighbors of each vertex.

Tail latency: Latency near a high percentile, such as p95 or p99.

Throughput: Completed operations per unit of time.

Scalability: The ability to maintain acceptable behavior as workload or resources change.

Locality: The tendency of a workload to reuse nearby or recently accessed data.

Benchmark: A controlled measurement experiment for comparing system behavior.

Amortized analysis: Analysis of average cost over a sequence of operations, including occasional expensive operations.

Total cost of ownership: The full development, runtime, operational, change, and risk cost of a decision.

Architecture decision record: A document recording a significant technical decision and its rationale.

Consistency: The degree to which observed data conforms to the system’s update rules.

Governance: Policies and controls for security, privacy, compliance, accountability, and lifecycle management.

Review Questions

Short Answer Questions

  1. Why should workload analysis precede data-structure selection?
  2. What assumptions are associated with expected O(1) hash-table lookup?
  3. Why is p99 latency often more useful than average latency for service-level objectives?
  4. State one strength and one limitation of a balanced search tree.
  5. What is the purpose of an architecture decision record?

Long Answer Questions

  1. Compare arrays, linked lists, hash tables, and balanced search trees for a system requiring exact lookup, ordered traversal, and frequent updates.
  2. Explain how a benchmark can produce misleading conclusions if it uses unrealistic data distributions or ignores tail latency.
  3. Discuss how horizontal scaling changes the trade-offs associated with an in-memory data structure.
  4. Explain why total cost of ownership includes operational and change costs in addition to infrastructure cost.
  5. Describe a complete process for selecting a data structure in an enterprise modernization project.

Analytical / Application Questions

  1. A service performs 70% exact lookups, 20% updates, and 10% range queries. Propose two candidate designs and explain which additional measurements would determine the better choice.
  2. A graph has 100,000 vertices and 200,000 edges. Determine whether an adjacency list or adjacency matrix is likely to be more space-efficient, and justify your answer using asymptotic reasoning.
  3. A team recommends a custom index because a microbenchmark shows a 15% speed improvement. Prepare a critique identifying performance, maintainability, security, operational, and governance evidence that should be gathered before approval.

Multiple Choice Questions with Answers

Question 1

Which workload most directly favors a hash table?

A. Frequent exact-key lookups with no ordering requirement

B. Frequent range queries over sorted keys

C. Repeated extraction of the highest-priority item

D. Shortest-path analysis over a network

Correct Answer: A. Frequent exact-key lookups with no ordering requirement

Question 2

What does the hash-table load factor α = n/m represent?

A. The number of collisions divided by the number of searches

B. The number of stored entries divided by the number of buckets

C. The number of buckets divided by the number of stored entries

D. The average time required for a lookup

Correct Answer: B. The number of stored entries divided by the number of buckets

Question 3

Why can p99 latency be more important than average latency?

A. It measures memory consumption exactly

B. It identifies the fastest request in a workload

C. It reveals behavior experienced by a high proportion of the slowest requests

D. It eliminates the need for repeated benchmarks

Correct Answer: C. It reveals behavior experienced by a high proportion of the slowest requests

Question 4

Which structure is most naturally suited to repeatedly removing the minimum-priority item?

A. Heap

B. Trie

C. Unsorted linked list only

D. Adjacency matrix

Correct Answer: A. Heap

Question 5

For a sparse graph, which representation usually uses less asymptotic space?

A. Adjacency matrix, because it stores every possible edge

B. Adjacency list, because it stores vertices and existing edges

C. Adjacency matrix, because vertices require no storage

D. Both always use the same space

Correct Answer: B. Adjacency list, because it stores vertices and existing edges

Question 6

In the weighted-score model, what should happen if a candidate violates a mandatory security requirement?

A. It should be selected if its performance score is highest

B. Its security rating should be ignored

C. It should normally be rejected regardless of its total score

D. It should be selected if its implementation is familiar

Correct Answer: C. It should normally be rejected regardless of its total score

Question 7

Which statement about dynamic-array insertion at the end is generally correct?

A. It is always O(n)

B. It is usually amortized O(1), although resizing can cost O(n)

C. It is always O(log n)

D. It cannot require memory allocation

Correct Answer: B. It is usually amortized O(1), although resizing can cost O(n)

Question 8

Which benchmark practice most improves workload validity?

A. Using only one small synthetic dataset

B. Measuring only the fastest trial

C. Using representative data, operation mixes, concurrency, and scaling levels

D. Ignoring memory and allocation behavior

Correct Answer: C. Using representative data, operation mixes, concurrency, and scaling levels

Question 9

What is a major advantage of a balanced search tree over a hash table?

A. It guarantees constant-time operations in every case

B. It naturally supports ordered traversal and range queries

C. It requires no memory for links or metadata

D. It prevents all concurrency problems

Correct Answer: B. It naturally supports ordered traversal and range queries

Question 10

Which item is part of total cost of ownership?

A. Only the initial purchase price

B. Only CPU utilization during a benchmark

C. Development, operation, change, and risk costs

D. Only the number of lines of source code

Correct Answer: C. Development, operation, change, and risk costs

Data Structures
Chapter 14 of 15