How to use the playground

1. Paste a function (or load an example)

Paste one Python function into the editor, or pick a built-in example — linear search, binary search, recursive factorial, and more — from the example menu. If you paste several functions, a selector appears so you can choose which one to analyze. Tell the app what n means for your input (for example "the size of arr") so the explanation uses your words.

2. Analyze — the 5-step derivation

Click Analyze(or press Ctrl/Cmd+Enter). You get the course's derivation: Step 0 shows the code; Step 1 establishes the variables and T(n); Step 2 counts the operations line by line; Step 3 writes the T(n) expression; Step 4 simplifies it; Step 5 states the Big-O. Read the assumptions and the confidence level — when the app is not sure, it says so rather than guessing, and some code is deliberately left as "needs instructor review".

3. Benchmark — measure it for real

Click Benchmark to run your function on growing inputs, safely inside your browser. The chart plots measured medians next to theoretical curves (O(1) up to O(2ⁿ)) drawn at true relative scale, with playback, zoom, and a log/linear toggle. Measured runtime and theoretical operation counts are different things: your machine, browser, and background load all shift the measurements, so treat the chart as evidence, not proof. Slow or runaway code is stopped automatically.

4. Optional: AI assistance

If you have an openrouter.ai API key, the AI panel (inside the analysis window) can reword the derivation or explain it step by step. Pick a model from the suggested free/paid lists or type any model id. AI output is always labelled "AI-assisted. Verify with DSA course rules." — the local analysis stays the primary answer. Your code is sent to OpenRouter only when you click an AI button; see About & privacy.

Common messages

  • "Python could not parse" / indentation errors: the paste is usually truncated or mis-indented; the message names the line to fix.
  • "features that are disabled": imports, file access, eval/exec and similar are blocked in the sandbox, so such code cannot be benchmarked.
  • "Unknown / needs instructor review": the pattern is outside what the app can count reliably — bring it to class.
  • The first benchmark is slow: the Python runtime (~10 MB) downloads once and is cached afterwards.