Skip to content
Data Structures and Algorithms / Linear Structures, Hashing, and the Sorting Toolkit

Arrays, Linked Lists, Stacks, and Queues

A tick-by-tick price feed, an order book, and a backtest's rolling window of returns are all, underneath the finance vocabulary, sequences: ordered collections you append to, read from, and occasionally trim. The single most consequential design decision for any such sequence — before a single line of pricing logic is written — is whether to store it as a contiguous array or as a linked list, because that choice fixes the cost of every operation you will ever run on it. This note builds the operation-cost table for both, then layers the stack and queue abstract data types (ADTs) on top, since both can be realised by either representation and each realisation has different trade-offs. Getting this right matters concretely: implementing a limit-order book's price levels as the wrong structure turns an O(1)O(1) insert into an O(n)O(n) one, and at high message rates that difference is the difference between a system that keeps up and one that doesn't.

In this lesson

  1. Learning objectives
  2. Arrays: contiguous memory, index arithmetic
  3. Linked lists: pointers, not addresses
  4. Stacks: last-in, first-out
  5. Queues: first-in, first-out

Before you start

The full lesson, with worked examples and exercise solutions, is for members.

Read the full lesson

New to SelfMadeQuant.com? See membership options or explore the curriculum.