Skip to content
Vega-Lite templates

Math — Chart: Algorithm Growth

Operations vs input size for different complexities.

Template previewVega-Lite
Rendering…

Make it your own.

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "description": "Algorithm growth rates",
  "data": {"values": [
    {"n": 10, "ops": 10, "kind": "O(n)"},
    {"n": 20, "ops": 20, "kind": "O(n)"},
    {"n": 40, "ops": 40, "kind": "O(n)"},
    {"n": 10, "ops": 33, "kind": "O(n log n)"},
    {"n": 20, "ops": 86, "kind": "O(n log n)"},
    {"n": 40, "ops": 213, "kind": "O(n log n)"},
    {"n": 10, "ops": 100, "kind": "O(n^2)"},
    {"n": 20, "ops": 400, "kind": "O(n^2)"},
    {"n": 40, "ops": 1600, "kind": "O(n^2)"}
  ]},
  "mark": {"type": "line", "point": true},
  "encoding": {
    "x": {"field": "n", "type": "quantitative", "title": "input size n"},
    "y": {"field": "ops", "type": "quantitative", "title": "operations"},
    "color": {"field": "kind", "type": "nominal", "title": "complexity"}
  }
}