{
  "openapi": "3.1.1",
  "info": {
    "title": "Big-O Crossover Calculator API",
    "version": "1.0.0",
    "summary": "When does c₁·n log n beat c₂·n²? Crossover points, log-log chart and run times.",
    "description": "Every endpoint performs the same calculation as the human page and returns inputs, result, units, assumptions, sources, warnings and computedAt. MCP endpoint: /mcp."
  },
  "servers": [
    {
      "url": "https://bigocrossovercalculator.usefulweb.site"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "When does c₁·n log n beat c₂·n²? Crossover points, log-log chart and run times.",
        "description": "Compares cost functions such as 50·n log n against 2·n² or 2ⁿ with your constant factors, finds every input size where one overtakes another, draws them on a log-log chart, and converts operation counts into running time at a given number of operations per second.\n\nMethodology:\n- Each cost is c·f(n) with log₂ for logarithms; n! is evaluated as Γ(n + 1), so every function is continuous in n. All comparisons are done on log10 of the cost, so 2ⁿ or n! for large n never overflow.\n- Crossovers: the difference of the log costs is sampled at 2,000 log-spaced sizes between the smallest and largest n; every sign change is refined by 80 bisection steps. Crossovers closer together than the grid spacing can be missed.\n- Time = cost ÷ operations per second. Real programs also depend on memory access, caches and constant overheads that a single constant c only approximates.",
        "tags": [
          "math"
        ],
        "x-mcp-tool": "big_o_crossover_calculator",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/BigOCrossoverCalculatorInput"
              },
              "examples": {
                "example1": {
                  "summary": "Merge sort vs insertion sort",
                  "value": {
                    "functions": [
                      {
                        "label": "Merge sort",
                        "complexity": "nlogn",
                        "constant": 6
                      },
                      {
                        "label": "Insertion sort",
                        "complexity": "n2",
                        "constant": 0.5
                      }
                    ]
                  }
                },
                "example2": {
                  "summary": "Brute force 2ⁿ vs n³ dynamic programming",
                  "value": {
                    "functions": [
                      {
                        "label": "Brute force",
                        "complexity": "2n",
                        "constant": 1
                      },
                      {
                        "label": "DP",
                        "complexity": "n3",
                        "constant": 100
                      },
                      {
                        "label": "Fancy n^2.37",
                        "complexity": "nk",
                        "constant": 1000000,
                        "exponent": 2.373
                      }
                    ],
                    "nMax": 100000,
                    "sizes": [
                      "10",
                      "20",
                      "30",
                      "50",
                      "100",
                      "1000"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BigOCrossoverCalculatorResult"
                }
              }
            }
          },
          "400": {
            "description": "Malformed JSON body.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Invalid input (see errors[]).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded (see Retry-After).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/tool": {
      "get": {
        "operationId": "getToolDefinition",
        "summary": "Inputs, output schema and examples for this tool",
        "responses": {
          "200": {
            "description": "Tool definition.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Problem": {
        "type": "object",
        "description": "RFC 9457 problem details. 422 responses include per-field `errors`.",
        "required": [
          "type",
          "title",
          "status",
          "detail"
        ],
        "properties": {
          "type": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer"
          },
          "detail": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "errors": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "field",
                "message"
              ],
              "properties": {
                "field": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "BigOCrossoverCalculatorInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "functions": {
            "title": "Cost functions",
            "type": "array",
            "minItems": 1,
            "maxItems": 8,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "label": {
                  "title": "Name",
                  "type": "string",
                  "maxLength": 40
                },
                "complexity": {
                  "title": "Growth",
                  "type": "string",
                  "enum": [
                    "1",
                    "logn",
                    "sqrtn",
                    "n",
                    "nlogn",
                    "n2",
                    "n3",
                    "nk",
                    "2n",
                    "nfact"
                  ],
                  "default": "n"
                },
                "constant": {
                  "title": "Constant c",
                  "type": "number",
                  "minimum": 1e-12,
                  "maximum": 1000000000000000,
                  "default": 1
                },
                "exponent": {
                  "title": "k (for n^k)",
                  "type": "number",
                  "minimum": 0,
                  "maximum": 20
                }
              },
              "required": [
                "complexity",
                "constant"
              ]
            },
            "default": [
              {
                "label": "Merge sort",
                "complexity": "nlogn",
                "constant": 6
              },
              {
                "label": "Insertion sort",
                "complexity": "n2",
                "constant": 0.5
              }
            ]
          },
          "nMin": {
            "title": "Smallest n",
            "type": "number",
            "minimum": 1,
            "maximum": 1000000000000,
            "default": 2
          },
          "nMax": {
            "title": "Largest n",
            "type": "number",
            "minimum": 2,
            "maximum": 1000000000000000,
            "default": 1000000
          },
          "opsPerSecond": {
            "title": "Operations per second",
            "description": "For converting cost into time; 10^9 is a rough figure for simple operations on one CPU core.",
            "type": "number",
            "minimum": 1,
            "maximum": 1000000000000000000,
            "default": 1000000000
          },
          "sizes": {
            "title": "Input sizes for the table",
            "type": "array",
            "items": {
              "type": "string"
            },
            "maxItems": 12,
            "default": [
              "10",
              "100",
              "1000",
              "10000",
              "100000",
              "1000000"
            ]
          }
        },
        "required": [
          "functions"
        ]
      },
      "BigOCrossoverCalculatorResult": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "schemaVersion",
          "tool",
          "computedAt",
          "inputs",
          "summary",
          "result",
          "units",
          "assumptions",
          "sources",
          "warnings",
          "presentation",
          "links"
        ],
        "properties": {
          "schemaVersion": {
            "type": "string",
            "const": "1.0"
          },
          "tool": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "id",
              "name",
              "version"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "version": {
                "type": "string"
              }
            }
          },
          "computedAt": {
            "type": "string",
            "format": "date-time"
          },
          "inputs": {
            "type": "object",
            "description": "Normalised inputs actually used, including applied defaults."
          },
          "summary": {
            "type": "string"
          },
          "result": {
            "type": "object",
            "required": [
              "functions",
              "crossovers",
              "table",
              "opsPerSecond"
            ],
            "properties": {
              "opsPerSecond": {
                "type": "number"
              },
              "functions": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": [
                    "label",
                    "formula"
                  ],
                  "properties": {
                    "label": {
                      "type": "string"
                    },
                    "formula": {
                      "type": "string"
                    }
                  }
                }
              },
              "crossovers": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": [
                    "between",
                    "n",
                    "cheaperAbove"
                  ],
                  "properties": {
                    "between": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    "n": {
                      "type": "number"
                    },
                    "firstIntegerN": {
                      "type": "integer"
                    },
                    "cheaperAbove": {
                      "type": "string"
                    }
                  }
                }
              },
              "table": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": [
                    "n",
                    "costs"
                  ],
                  "properties": {
                    "n": {
                      "type": "number"
                    },
                    "costs": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "label",
                          "log10Ops",
                          "ops",
                          "time"
                        ],
                        "properties": {
                          "label": {
                            "type": "string"
                          },
                          "log10Ops": {
                            "type": [
                              "number",
                              "null"
                            ]
                          },
                          "ops": {
                            "type": "string"
                          },
                          "time": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              },
              "cheapestAtMax": {
                "type": "string"
              }
            }
          },
          "units": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "assumptions": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "sources": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "title"
              ],
              "properties": {
                "title": {
                  "type": "string"
                },
                "url": {
                  "type": "string"
                },
                "publisher": {
                  "type": "string"
                },
                "retrievedAt": {
                  "type": "string"
                },
                "note": {
                  "type": "string"
                }
              }
            }
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "presentation": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "description": "Display blocks used by the human page (same data)."
          },
          "links": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "human",
              "api",
              "openapi",
              "methodology"
            ],
            "properties": {
              "human": {
                "type": "string",
                "format": "uri"
              },
              "api": {
                "type": "string",
                "format": "uri"
              },
              "openapi": {
                "type": "string",
                "format": "uri"
              },
              "methodology": {
                "type": "string",
                "format": "uri"
              }
            }
          }
        }
      }
    }
  }
}