← Course home

Python reference · Reference

Analysis and library costs

Estimate the work and memory an algorithm uses, including the cost of common Python operations.

ReferenceAbout 2 min

This page lists the library modules for Analysis and library costs. The lesson is Cost models and assumptions.

This page is the module index for analysis and library costs.

This legacy page is a short map to the foundation sequence: input size and operation counts, asymptotic growth, cost models, loop invariants, array and Python sequence costs, and recursion and recurrences.

  • bitsandbytes/complexity.py — word RAM model, O/Θ/Ω vocabulary, recursion limit, and the three recurrence shapes (merge divide, halving, linear decrement).
  • bitsandbytes/library_costs.py — why BFS uses deque, heapq.nsmallest, bisect.insort, and Timsort; list.pop(0) costs O(n) element moves.

Industry

A working engineer checks the language cost table before replacing a loop. Python's time-complexity documentation lists list.pop(0) as O(n), because every later element moves, and says to use a collections.deque when both ends change. That deque documents approximately the same O(1) cost for appends and pops in either direction.

Implementation and tests Optional reference

Library code 2

  • bitsandbytes.complexity
  • bitsandbytes.library_costs

Use these references to compare the explanation with repository code and tests. A test link means it imports a lesson symbol; it does not by itself claim complete behavior coverage.