liveBook · Manning

Cost

As explained in Grokking AI Algorithms, Second Edition

Computational cost is the processing effort required by a function or algorithm, commonly measured by operations or execution time.

Computational cost is the processing effort required by a function or algorithm. It is commonly understood through the number of operations needed as input size grows. Lower growth usually means better scaling, especially on large datasets. section 2.2

Big O notation gives a simple way to compare how operation counts grow:

  • O(1) stays roughly constant, like shaking hands with one person regardless of the crowd. section 2.2
  • O(n) grows with the input, like shaking hands with everyone in a room. section 2.2
  • O(n²) compares every item with every other item, causing costs to rise rapidly. section 2.2

Cost is not the only practical concern. Memory use, hardware efficiency, parallel processing, energy consumption, and response latency can change which algorithm or model is preferable. A slower algorithm may still run faster when distributed across many processors, such as GPUs. section 2.2 section 11.11

Choosing an LLM architecture

Training a large language model with a huge vocabulary requires substantial processing power and energy. Larger architectures can capture more nuance, but training may require weeks or months on clusters of thousands of GPUs. The design therefore balances compute cost with memory capacity and latency: a capable model that takes too long to respond may not suit an interactive chatbot. section 11.11

Figure 2.3 Big O complexity

Compare how constant, linear, and quadratic operation counts grow as input size increases. section 2.2

How Grokking AI Algorithms, Second Edition covers it

How deep it goes
Defines Big O through constant, linear, and quadratic examples, then compares compute cost with memory, hardware efficiency, energy, and latency.
Examples
Uses handshaking analogies, list iteration, pairwise comparison, and large-language-model training on GPU clusters.
What it assumes
Assumes familiarity with inputs, algorithms, and basic neural-network terminology while introducing Big O through concrete analogies.
What you can do after
Evaluate algorithms and model architectures by comparing operation growth, hardware demands, energy use, memory needs, and latency.
How it connects
Connects computational cost to Big O notation, algorithms, memory use, parallel processing, GPUs, neural networks, LLMs, and latency.

Also explained in

Compare how 10 books explain cost →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking AI Algorithms, Second Edition. The section links point to the parts of the book it draws on.