MetoolzyMetoolzy

Big O Cheat Sheet

算法和数据结构的时间和空间复杂度交互式参考。

Complexity Growth Chart

050100150200250300051015202530Elements (n)Operations
O(1)O(log n)O(n)O(n log n)O(n²)O(2ⁿ)

Sorting Algorithms

AlgorithmBestAverageWorstSpaceStable
Bubble SortO(n)O(n²)O(n²)O(1)Yes
Selection SortO(n²)O(n²)O(n²)O(1)No
Insertion SortO(n)O(n²)O(n²)O(1)Yes
Merge SortO(n log n)O(n log n)O(n log n)O(n)Yes
Quick SortO(n log n)O(n log n)O(n²)O(log n)No
Heap SortO(n log n)O(n log n)O(n log n)O(1)No
Counting SortO(n+k)O(n+k)O(n+k)O(k)Yes
Radix SortO(nk)O(nk)O(nk)O(n+k)Yes
Tim SortO(n)O(n log n)O(n log n)O(n)Yes

Data Structure Operations

Each cell shows Average / Worst case complexity.

Data StructureAccessSearchInsertDelete
ArrayO(1)/O(1)O(n)/O(n)O(n)/O(n)O(n)/O(n)
StackO(n)/O(n)O(n)/O(n)O(1)/O(1)O(1)/O(1)
QueueO(n)/O(n)O(n)/O(n)O(1)/O(1)O(1)/O(1)
Linked ListO(n)/O(n)O(n)/O(n)O(1)/O(1)O(1)/O(1)
Hash Table—/—O(1)/O(n)O(1)/O(n)O(1)/O(n)
BSTO(log n)/O(n)O(log n)/O(n)O(log n)/O(n)O(log n)/O(n)
AVL TreeO(log n)/O(log n)O(log n)/O(log n)O(log n)/O(log n)O(log n)/O(log n)
B-TreeO(log n)/O(log n)O(log n)/O(log n)O(log n)/O(log n)O(log n)/O(log n)
Red-BlackO(log n)/O(log n)O(log n)/O(log n)O(log n)/O(log n)O(log n)/O(log n)

Common Algorithms

AlgorithmTimeSpace
Binary SearchO(log n)O(1)
BFSO(V+E)O(V)
DFSO(V+E)O(V)
DijkstraO((V+E)log V)O(V)
Bellman-FordO(VE)O(V)
Floyd-WarshallO(V³)O(V²)

Interactive Chart

Hover over the growth chart to compare operations at any input size.

Common Complexities

O(1) to O(n!) — all major complexity classes with color-coded badges.

Code Examples

Sorting algorithms, data structures, and graph algorithms at a glance.

Comparison

Side-by-side tables for best, average, worst case and space complexity.

关于Big O Cheat Sheet

The Big O Notation Cheat Sheet is a comprehensive reference for algorithm and data structure time and space complexity. Big O notation describes how an algorithm's performance scales with input size — understanding it is essential for writing efficient code, passing technical interviews, and making informed architectural decisions. This tool provides an interactive growth chart where you can hover to compare how many operations different complexity classes require at any input size, plus reference tables for 9 sorting algorithms, 9 data structures, and 6 common graph and search algorithms. Each entry shows best, average, and worst-case time complexity and space complexity with colour-coded badges from green (efficient O(1), O(log n)) to red (avoid O(n²), O(2ⁿ)). Stability of sorting algorithms is also noted.

如何使用Big O Cheat Sheet

  1. Hover over the Complexity Growth Chart to see the exact operation count for each complexity class at a given input size n.
  2. Study the colour coding: green = fast (O(1), O(log n)), yellow = acceptable (O(n)), orange = moderate (O(n log n)), red = slow (O(n²), O(2ⁿ)).
  3. Use the Sorting Algorithms table to compare sorting choices — remember Quick Sort has O(n²) worst case while Merge Sort guarantees O(n log n).
  4. Use the Data Structures table to choose the right structure — Hash Tables give O(1) average search but O(n) worst case; AVL Trees guarantee O(log n) for all operations.
  5. Check the Common Algorithms section for standard graph algorithm complexities (BFS, DFS, Dijkstra, Floyd-Warshall).
  6. Use the Stable column when selecting a sort for data where the order of equal elements matters.

常见问题

What is Big O notation and why does it matter?

Big O notation describes the upper bound of how an algorithm's runtime or memory usage grows as the input size n increases. It matters because an algorithm that works fine for 100 items may be completely unusable for 1,000,000 items. O(n²) at n=1000 means 1,000,000 operations; O(n log n) at n=1,000,000 means only ~20,000,000 — a 50× difference that becomes billions× at larger scales.

What is the difference between time complexity and space complexity?

Time complexity measures how the number of operations grows with input size. Space complexity measures how much extra memory the algorithm needs. For example, Merge Sort has O(n log n) time but O(n) space because it needs a temporary copy of the array. In-place algorithms like Heap Sort use O(1) extra space at the cost of more complex implementation.

Why does Hash Table have O(n) worst-case search?

Hash Tables achieve O(1) average search because keys are distributed across buckets using a hash function. In the worst case (a very poor hash function or many hash collisions), all keys end up in the same bucket, degenerating into a linked list with O(n) search. Good hash functions and load factor management (rehashing) keep the average near O(1).

When should I choose Merge Sort over Quick Sort?

Choose Merge Sort when: (1) you need guaranteed O(n log n) worst-case performance and cannot afford the O(n²) worst case of Quick Sort on sorted or adversarially chosen input, (2) you need a stable sort, or (3) you are sorting linked lists where random access is expensive. Choose Quick Sort when average performance matters more and you want in-place sorting with low cache miss rates.

What is amortized complexity and how does it relate to Big O?

Amortized complexity describes the average cost per operation over a sequence of operations, even if individual operations occasionally take longer. For example, dynamic arrays (like JavaScript arrays or Python lists) have O(1) amortized push even though they occasionally need O(n) to resize and copy — because resizes happen infrequently enough that the average cost per push is still O(1).

Big O Cheat Sheet 完全使用指南与免费在线工具

无需安装、完全免费、纯前端本地运行的高效 Big O Cheat Sheet 工具

用于快速解决:算法和数据结构的时间和空间复杂度交互式参考。。无需安装复杂软件,打开网页即可立即使用,极速且安全。

为什么选择 Metoolzy 的 Big O Cheat Sheet?

  • 秒级即时响应: 极致性能优化,输入即可见结果。
  • 数据绝对安全: 纯浏览器本地计算,数据绝不上传服务器。
  • 完全免费使用: 无需注册登录,无任何隐形消费。

三步快速上手

  1. 打开 Metoolzy Big O Cheat Sheet 工具页面。
  2. 在输入区粘贴或上传您的数据。
  3. 即时查看处理结果并点击复制或下载。

功能对比表

对比项 Metoolzy Big O Cheat Sheet 普通在线工具 本地客户端软件
使用成本 永久免费 有次数限制或收费 需购买授权
隐私保护 纯本地内存运行 数据需上传云端 本地运行

适用人群与应用场景

  • 软件开发人员日常调试与数据转换
  • UI/UX 设计师资产处理
  • 运营与办公人员效率提升

常见问题解答 (FAQ)

处理的数据会被记录或保存吗?

绝不会。所有运算均在您的浏览器本地完成,没有任何数据回传。