Complexity Table
Complexity Table
Structured time and space complexity table for algorithm documentation
Installation
npx @ravikumarsurya/mdx-ui add complexity-tableUsage
import { ComplexityTable } from "@/components/mdx/complexity-table";
<ComplexityTable
rows={[
{ operation: "Search", best: "O(1)", average: "O(log n)", worst: "O(n)" },
{
operation: "Insert",
best: "O(log n)",
average: "O(log n)",
worst: "O(n)",
},
]}
/>;Examples
| Operation | Best | Average | Worst | Space |
|---|---|---|---|---|
| Search | O(1) | O(log n) | O(n) | O(1) |
| Insert | O(1) | O(log n) | O(n) | O(1) |
| Delete | O(1) | O(log n) | O(n) | O(1) |
| Traverse | O(n) | O(n) | O(n) | O(n) |
Binary Search Tree — time and space complexity
BST operations
<ComplexityTable
rows={[
{ operation: "Search", best: "O(1)", average: "O(log n)", worst: "O(n)" },
{
operation: "Insert",
best: "O(log n)",
average: "O(log n)",
worst: "O(n)",
},
{
operation: "Delete",
best: "O(log n)",
average: "O(log n)",
worst: "O(n)",
},
]}
caption="Binary Search Tree — unbalanced worst case"
/>With space complexity
<ComplexityTable
rows={[
{
operation: "Merge Sort",
best: "O(n log n)",
average: "O(n log n)",
worst: "O(n log n)",
space: "O(n)",
},
{
operation: "Quick Sort",
best: "O(n log n)",
average: "O(n log n)",
worst: "O(n²)",
space: "O(log n)",
},
{
operation: "Heap Sort",
best: "O(n log n)",
average: "O(n log n)",
worst: "O(n log n)",
space: "O(1)",
},
]}
/>Sparse columns
Only columns that have data in at least one row are rendered. Missing values show as —.
<ComplexityTable
rows={[
{ operation: "Lookup", worst: "O(1)" },
{ operation: "Resize", worst: "O(n)" },
]}
/>Props
ComplexityTable
| Prop | Type | Default | Description |
|---|---|---|---|
rows | ComplexityRow[] | — | Array of operation rows (required) |
caption | string | — | Optional caption below the table |
className | string | — | Additional CSS classes |
ComplexityRow
| Field | Type | Description |
|---|---|---|
operation | string | Operation name (required) |
best | string | Best-case complexity |
average | string | Average-case complexity |
worst | string | Worst-case complexity |
space | string | Space complexity |