From b452a5f0fdae279b237b44a04fe19fa380db1f43 Mon Sep 17 00:00:00 2001 From: mmdmthr Date: Sat, 13 Jul 2024 21:25:52 +0700 Subject: [PATCH] 89 add article big o notation cheatseet --- content/blog/2024/07/big-o-notation-cheatseet.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 content/blog/2024/07/big-o-notation-cheatseet.md diff --git a/content/blog/2024/07/big-o-notation-cheatseet.md b/content/blog/2024/07/big-o-notation-cheatseet.md new file mode 100644 index 0000000..43e542a --- /dev/null +++ b/content/blog/2024/07/big-o-notation-cheatseet.md @@ -0,0 +1,16 @@ +--- +title: 'Big O Notation Cheatseet' +date: 2024-07-13 +category: 'notes' +--- + +|Notation |Name |Description |Example (Time complexity) | +|---|---|---|---| +| O(1) | Constant complexity | The time and space consumed is consistent regardless of input size | Retrieving a value from a hash table given a specific key | +| O(log n) | Logarithmic complexity | The time and space consumed grows logarithmically with the input size | Binary search on a sorted array | +|O(n) | Linear complexity | The time and space consumed grows in direct proportion to the input size | Searching for a single element in an array (looping over an array) | +| O(n log n) | Linearithmic complexity | The time and space consumed grows proportionally to n log n (where n is the size of the input) | Efficient sorting algorithms like quicksort | +| O(n^2) | Quadratic complexity | The time and space consumed grows with the square of the input size | simple sorting algorithms like bubble sort. looping over an array, and comparing the current element with all other elements in the array | +| O(n^3) | Cubic complexity | The time and space consumed grows with the cube of the input size | Triple nested loops | +| O(2^n) | Exponential complexity | The time and space consumed doubles with eacch increment to the input size | Recursive calculation if Fibonacci numbers | +| O(n!) | Factorial complexity | The time and space consumed grows factorially to the size of the input | Solving the traveling salesman problem with brute force | \ No newline at end of file