HiveBrain v1.2.0
Get Started
← Back to all entries
snippetjavascriptTip

Big-O Cheat Sheet

Submitted by: @import:30-seconds-of-code··
0
Viewed 0 times
javascriptbigcheatsheet

Problem

Big-O notation, represents an algorithm's worst-case complexity. It uses algebraic terms to describe the complexity of an algorithm, allowing you to measure its efficiency and performance. Below you can find a chart that illustrates Big-O complexity:
!Big-O Complexity Chart
Simply put, O(1) stands for constant time complexity, which is the most efficient, while O(n!) stands for factorial time complexity, which is the least efficient. The n in the complexity represents the size of the input, so O(n) means that the algorithm's time complexity will grow linearly with the size of the input.
Apart from Big-O notation, there are other notations that are used to describe the complexity of an algorithm, such as Ω (Omega) and Θ (Theta). Ω describes the best-case complexity of an algorithm, while Θ describes the average-case complexity of an algorithm.
Different data structures have different time complexities for the same operations. For example, a linked list has O(1) time complexity for insert and delete operations, while an array has O(n) time complexity for the same operations. Below you can find average and worst time complexities for data structures used commonly in web development.

Solution

Simply put, O(1) stands for constant time complexity, which is the most efficient, while O(n!) stands for factorial time complexity, which is the least efficient. The n in the complexity represents the size of the input, so O(n) means that the algorithm's time complexity will grow linearly with the size of the input.
Apart from Big-O notation, there are other notations that are used to describe the complexity of an algorithm, such as Ω (Omega) and Θ (Theta). Ω describes the best-case complexity of an algorithm, while Θ describes the average-case complexity of an algorithm.
Different data structures have different time complexities for the same operations. For example, a linked list has O(1) time complexity for insert and delete operations, while an array has O(n) time complexity for the same operations. Below you can find average and worst time complexities for data structures used commonly in web development.
| Data Structure | Access | Search | Insertion | Deletion |
| --- | --- | --- | --- | --- |
| Array | Θ(1) | Θ(n) | Θ(n) | Θ(n) |

Context

From 30-seconds-of-code: big-o-cheatsheet

Revisions (0)

No revisions yet.