From 3af36e5f41326e25bebe4840bbc85225d0c275f7 Mon Sep 17 00:00:00 2001 From: Shubham Jain Date: Thu, 1 Oct 2020 23:30:15 +0530 Subject: [PATCH 1/6] Create space-time-complexity-cheatsheat.md --- DSA/space-time-complexity-cheatsheat.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 DSA/space-time-complexity-cheatsheat.md diff --git a/DSA/space-time-complexity-cheatsheat.md b/DSA/space-time-complexity-cheatsheat.md new file mode 100644 index 0000000..8e81f47 --- /dev/null +++ b/DSA/space-time-complexity-cheatsheat.md @@ -0,0 +1,3 @@ +# Space And Time Complexity of Algorithms + +## Whay is Complexity ? From 39d2e57b3acc09636b528a468109957523474765 Mon Sep 17 00:00:00 2001 From: Shubham Jain Date: Thu, 1 Oct 2020 23:30:53 +0530 Subject: [PATCH 2/6] Update Published-Topics.md --- DSA/Published-Topics.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DSA/Published-Topics.md b/DSA/Published-Topics.md index e69de29..295f325 100644 --- a/DSA/Published-Topics.md +++ b/DSA/Published-Topics.md @@ -0,0 +1 @@ +Space And Time Complexity Cheatsheet From 05257e9ade10a239bd97e221de35cb19a58db8b1 Mon Sep 17 00:00:00 2001 From: Shubham Jain Date: Thu, 1 Oct 2020 23:31:09 +0530 Subject: [PATCH 3/6] Update Published-Topics.md --- DSA/Published-Topics.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DSA/Published-Topics.md b/DSA/Published-Topics.md index 295f325..f6e33e6 100644 --- a/DSA/Published-Topics.md +++ b/DSA/Published-Topics.md @@ -1 +1 @@ -Space And Time Complexity Cheatsheet +1. Space And Time Complexity Cheatsheet From 43fe22067835422694719ee1c814f667e46076c5 Mon Sep 17 00:00:00 2001 From: Shubham Jain Date: Fri, 2 Oct 2020 00:50:55 +0530 Subject: [PATCH 4/6] Update space-time-complexity-cheatsheat.md --- DSA/space-time-complexity-cheatsheat.md | 62 ++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/DSA/space-time-complexity-cheatsheat.md b/DSA/space-time-complexity-cheatsheat.md index 8e81f47..72a3629 100644 --- a/DSA/space-time-complexity-cheatsheat.md +++ b/DSA/space-time-complexity-cheatsheat.md @@ -1,3 +1,63 @@ # Space And Time Complexity of Algorithms -## Whay is Complexity ? + + +## 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 time complexities of various commonly used algorithms: + +| Name of Algorithm | Best 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) | From 8cb61ea16aab9a03d695c612d970db3e456d1e03 Mon Sep 17 00:00:00 2001 From: Shubham Jain Date: Fri, 2 Oct 2020 10:29:20 +0530 Subject: [PATCH 5/6] Update space-time-complexity-cheatsheat.md --- DSA/space-time-complexity-cheatsheat.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DSA/space-time-complexity-cheatsheat.md b/DSA/space-time-complexity-cheatsheat.md index 72a3629..fae637c 100644 --- a/DSA/space-time-complexity-cheatsheat.md +++ b/DSA/space-time-complexity-cheatsheat.md @@ -49,7 +49,7 @@ Similar to time complexity, it is also denoted by **Big - O** notation. ### Space Complexity of various algorithms -Following table contains time complexities of various commonly used algorithms: +Following table contains space complexities of various commonly used algorithms: | Name of Algorithm | Best Case | | :---------------: | :---------: | From eb7db9bdbe3be8937498b98c9be75c92752bde1d Mon Sep 17 00:00:00 2001 From: Shubham Jain Date: Fri, 2 Oct 2020 10:29:52 +0530 Subject: [PATCH 6/6] Update space-time-complexity-cheatsheat.md --- DSA/space-time-complexity-cheatsheat.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DSA/space-time-complexity-cheatsheat.md b/DSA/space-time-complexity-cheatsheat.md index fae637c..4cb4deb 100644 --- a/DSA/space-time-complexity-cheatsheat.md +++ b/DSA/space-time-complexity-cheatsheat.md @@ -51,7 +51,7 @@ Similar to time complexity, it is also denoted by **Big - O** notation. Following table contains space complexities of various commonly used algorithms: -| Name of Algorithm | Best Case | +| Name of Algorithm | Worst Case | | :---------------: | :---------: | | Selection Sort | Ω(n^2) | | Bubble Sort | Ω(n) |