Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DSA/Published-Topics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1. Space And Time Complexity Cheatsheet
63 changes: 63 additions & 0 deletions DSA/space-time-complexity-cheatsheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Space And Time Complexity of Algorithms



## What is Time Complexity ?

##### Time Complexity is the computational complexity that describes the amount of time it takes to run an algorithm. It is generally estimated by counting the number of elementary operations performed by the algorithm, supposing that each operation takes a fixed amount of time.

It is generally denoted by **Big- O** notation.

Since running time of Algorithms can vary *a lot* on their input, we commonly consider the **worst-case** time complexity of algorithms.

Assuming that the size of the input is represented by n and constant value is represented by k. Some common time complexities, in increasing order, are:

```
O(k) < O(log(n)) < O(n*log(n)) < O(n^k) < O(k^n) < O(n!) and so on...
```



### Time Complexity of various algorithms

Following table contains time complexities of various commonly used algorithms:




Name of Algorithm | Best Case|Worst Case | Average Case
:----------: | :-----------: | :-----------: | :-----------:
Selection Sort |Ω(n^2)| θ(n^2) | O(n^2)
Bubble Sort | Ω(n) |θ(n^2) | O(n^2)
Insertion Sort | Ω(n) | θ(n^2) | O(n^2)
Heap Sort | Ω(n log(n))| θ(n log(n))| O(n log(n))
Quick Sort | Ω(n log(n)) | θ(n log(n)) | O(n^2)
Merge Sort | Ω(n log(n)) | θ(n log(n)) | O(n log(n))
Bucket Sort | Ω(n+k) | θ(n+k) | O(n^2)
Radix Sort | Ω(nk) | θ(nk) | O(nk)




## What is Space Complexity?

##### The **space complexity** of an algorithm or a computer program is the amount of memory space required to solve an instance of the computational problem as a function of characteristics of the input. It is the memory required by an algorithm to execute a program and produce output.

Similar to time complexity, it is also denoted by **Big - O** notation.



### Space Complexity of various algorithms

Following table contains space complexities of various commonly used algorithms:

| Name of Algorithm | Worst Case |
| :---------------: | :---------: |
| Selection Sort | Ω(n^2) |
| Bubble Sort | Ω(n) |
| Insertion Sort | Ω(n) |
| Heap Sort | Ω(n log(n)) |
| Quick Sort | Ω(n log(n)) |
| Merge Sort | Ω(n log(n)) |
| Bucket Sort | Ω(n+k) |
| Radix Sort | Ω(n*k) |