Skip to content

Commit 70ed21f

Browse files
committed
Now added new content for Time Complexity
1 parent 1ebc6eb commit 70ed21f

File tree

4 files changed

+149
-4
lines changed

4 files changed

+149
-4
lines changed

docusaurus.config.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,24 @@ const config = {
8282
backgroundColor: "var(--ifm-color-primary)",
8383
},
8484

85+
metadata: [
86+
{
87+
name: "keywords",
88+
content:
89+
"CodeHarborHub, CodeHarbor, CodeHarborHub, CodeHarborHub Blog, CodeHarborHub Community, CodeHarborHub Courses, CodeHarborHub DSA, CodeHarborHub Web Dev, CodeHarborHub Tutorials, CodeHarborHub Showcase, CodeHarborHub Donate, CodeHarborHub Blog, CodeHarborHub Team, CodeHarborHub About, CodeHarborHub Contact, CodeHarborHub Careers, CodeHarborHub Terms, CodeHarborHub Privacy, CodeHarborHub Cookie, CodeHarborHub Code of Conduct, CodeHarborHub Quiz, CodeHarborHub Broadcast, CodeHarborHub Tags, CodeHarborHub Courses Tags, CodeHarborHub DSA Tags, CodeHarborHub Web Dev Tags, CodeHarborHub Product, CodeHarborHub LinkedIn, CodeHarborHub YouTube, CodeHarborHub Discord, CodeHarborHub Twitter, CodeHarborHub GitHub, CodeHarborHub Products, CodeHarborHub Web Dev, CodeHarborHub DSA, CodeHarborHub Courses, CodeHarborHub Tutorials, CodeHarborHub Showcase, CodeHarborHub Donate, CodeHarborHub Blog, CodeHarborHub Team, CodeHarborHub About, CodeHarborHub Contact, CodeHarborHub Careers, CodeHarborHub Terms, CodeHarborHub Privacy, CodeHarborHub Cookie, CodeHarborHub Code of Conduct, CodeHarborHub Quiz, CodeHarborHub Broadcast, CodeHarborHub Tags, CodeHarborHub Courses Tags, CodeHarborHub DSA Tags, CodeHarborHub Web Dev Tags, CodeHarborHub Product, CodeHarborHub LinkedIn, CodeHarborHub YouTube, CodeHarborHub Discord, CodeHarborHub Twitter, CodeHarborHub GitHub, CodeHarborHub Products, CodeHarborHub Web Dev, CodeHarborHub DSA, CodeHarborHub Courses, CodeHarborHub Tutorials, CodeHarborHub Showcase, CodeHarborHub Donate, CodeHarborHub Blog, CodeHarborHub Team, CodeHarborHub About, CodeHarborHub Contact, CodeHarborHub Careers, CodeHarborHub Terms, CodeHarborHub Privacy, CodeHarborHub Cookie, CodeHarborHub Code of Conduct, CodeHarborHub Quiz, CodeHarborHub Broadcast, CodeHarborHub Tags, CodeHarborHub, leetcode, codeforces, hackerrank, geeksforgeeks, interviewbit, educative, udemy, coursera, udacity, khanacademy, codecademy, w3schools, tutorialspoint, javatpoint, geeksforgeeks, stackoverflow, github, gitlab, bitbucket, codepen, jsfiddle, repl.it, codesandbox, stackblitz, gfg, GeeksForGeeks, tech",
90+
},
91+
{ name: "twitter:card", content: "summary_large_image" },
92+
{ name: "twitter:site", content: "@CodesWithAjay" },
93+
{ name: "twitter:creator", content: "@CodesWithAjay" },
94+
{ property: "og:type", content: "website" },
95+
{ property: "og:site_name", content: "CodeHarborHub" },
96+
{ property: "og:title", content: "CodeHarborHub - A place to learn and grow" },
97+
{ property: "og:description", content: "CodeHarborHub is a place to learn and grow. We provide accessible and comprehensive educational resources to learners of all levels, from beginners to advanced professionals."},
98+
{ property: "og:image", content: "https://codeharborhub.github.io/img/nav-logo.jpg" },
99+
{ property: "og:url", content: "https://codeharborhub.github.io" },
100+
{ name: "robots", content: "index, follow" },
101+
],
102+
85103
algolia: {
86104
apiKey: "2c1a3331ebff51f76d2f247323ee4ba4",
87105
indexName: "code-harbor-hub",
@@ -175,19 +193,19 @@ const config = {
175193

176194
{
177195
to: "/our-sponsors/",
178-
html: '<span class="nav-emoji">💰</span> Donate'
196+
html: '<span class="nav-emoji">💰</span> Donate',
179197
},
180198

181199
{
182200
to: "/blog",
183201
html: '<span class="nav-emoji">📰</span> Blog',
184202
},
185-
203+
186204
{
187205
type: "dropdown",
188206
html: '<span class="nav-emoji">🔗</span> More',
189207
position: "left",
190-
items: [
208+
items: [
191209
{
192210
html: '<span class="nav-emoji">🌍</span> Web Dev',
193211
to: "/web-dev/",

dsa/basic-topics/introduction.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ id: introduction-to-data-structures-and-algorithms
33
title: Introduction to Data Structures and Algorithms
44
sidebar_label: Introduction to DSA
55
sidebar_position: 1
6+
tags: [data-structures, algorithms, introduction, basics, dsa]
7+
description: 'An introduction to Data Structures and Algorithms (DSA) and why they are important in computer science.'
68
---
79

810
Data Structures and Algorithms (DSA) is a fundamental part of computer science. It is the study of data structures and algorithms that are used to solve problems. Data structures are a way of organizing and storing data so that it can be accessed and modified efficiently. Algorithms are a set of instructions that are used to solve problems.
@@ -54,5 +56,5 @@ Data structures and algorithms are essential topics in computer science. They pr
5456
<h2>Authors:</h2>
5557

5658
{['ajay-dhangar'].map(username => (
57-
<Author key={username} username={username} />
59+
<Author key={username} username={username} />
5860
))}

dsa/basic-topics/time-complexity.md

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,126 @@ title: Time Complexity
44
sidebar_label: Time Complexity
55
sidebar_position: 2
66
---
7+
8+
<head>
9+
<meta name="description" content="Learn about time complexity in algorithms, including types like constant, logarithmic, linear, and more. Understand Big O notation, common analysis techniques, and practical examples." />
10+
<meta name="keywords" content="Time Complexity, Big O Notation, Algorithm Analysis, Constant Time, Logarithmic Time, Linear Time, Quadratic Time, Exponential Time, Factorial Time, Amortized Analysis, Probabilistic Analysis, Complexity Classes, Algorithm Efficiency" />
11+
<meta name="author" content="ajay-dhangar" />
12+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
13+
14+
<meta property="og:title" content="Understanding Time Complexity in Algorithms" />
15+
<meta property="og:description" content="A comprehensive guide to time complexity in algorithms, covering different types, Big O notation, analysis techniques, and practical examples." />
16+
<meta property="og:type" content="article" />
17+
<meta property="og:url" content="https://codeharborhub.github.io/dsa/basic-topics/time-complexity/" />
18+
<meta property="og:image" content="https://codeharborhub.github.io/img/nav-logo.jpg" />
19+
<meta property="og:site_name" content="CodeHarborHub" />
20+
<meta property="og:locale" content="en_US" />
21+
22+
</head>
23+
24+
25+
Time complexity is a measure of the amount of time an algorithm takes to run as a function of the length of the input. It is an important concept in computer science and is used to analyze the efficiency of algorithms. Time complexity is typically expressed using Big $O$ notation, which provides an upper bound on the growth rate of an algorithm.
26+
27+
## Types of Time Complexity
28+
29+
There are several types of time complexity that are commonly used to analyze algorithms. Some of the most common types of time complexity include:
30+
31+
1. **Constant Time ($ O(1) $)**: An algorithm is said to have constant time complexity if the time it takes to run is independent of the size of the input. This means that the algorithm takes the same amount of time to run, regardless of the size of the input.
32+
2. **Logarithmic Time ($ O(\log n) $)**: An algorithm is said to have logarithmic time complexity if the time it takes to run grows logarithmically with the size of the input. This means that the algorithm takes less time to run as the size of the input increases.
33+
3. **Linear Time ($ O(n) $)**: An algorithm is said to have linear time complexity if the time it takes to run grows linearly with the size of the input. This means that the algorithm takes more time to run as the size of the input increases.
34+
4. **Quadratic Time ($ O(n^2) $)**: An algorithm is said to have quadratic time complexity if the time it takes to run grows quadratically with the size of the input. This means that the algorithm takes even more time to run as the size of the input increases.
35+
5. **Exponential Time ($ O(2^n) $)**: An algorithm is said to have exponential time complexity if the time it takes to run grows exponentially with the size of the input. This means that the algorithm takes a very long time to run as the size of the input increases.
36+
6. **Cubic Time ($ O(n^3) $)**: An algorithm is said to have cubic time complexity if the time it takes to run grows cubically with the size of the input. This means that the algorithm takes even more time to run as the size of the input increases.
37+
7. **Factorial Time ($ O(n!) $)**: An algorithm is said to have factorial time complexity if the time it takes to run grows factorially with the size of the input. This means that the algorithm takes an extremely long time to run as the size of the input increases.
38+
8. **Linearithmic Time ($ O(n \log n) $)**: An algorithm is said to have linearithmic time complexity if the time it takes to run grows linearithmically with the size of the input. This means that the algorithm takes more time to run as the size of the input increases, but not as much as a quadratic or exponential algorithm.
39+
40+
## Analyzing Time Complexity
41+
42+
There are several techniques that can be used to analyze the time complexity of an algorithm. Some of the most common techniques include:
43+
44+
- **Big $O$ Notation**: Big $O$ notation is used to describe the upper bound on the growth rate of an algorithm. It provides a way to compare the efficiency of different algorithms and determine how the running time of an algorithm grows as the size of the input increases.
45+
- **Big $\Omega$ Notation**: Big $\Omega$ notation is used to describe the lower bound on the growth rate of an algorithm. It provides a way to determine the best-case running time of an algorithm.
46+
- **Big $\Theta$ Notation**: Big $\Theta$ notation is used to describe the tight bound on the growth rate of an algorithm. It provides a way to determine the average-case running time of an algorithm.
47+
48+
## Common Algorithm Analysis Techniques
49+
50+
There are several common algorithm analysis techniques that can be used to analyze the time complexity of an algorithm. Some of the most common techniques include:
51+
52+
1. **Worst-Case Analysis**: Worst-case analysis is used to determine the maximum amount of time an algorithm will take to run on a given input. It provides an upper bound on the running time of an algorithm.
53+
2. **Average-Case Analysis**: Average-case analysis is used to determine the average amount of time an algorithm will take to run on a given input. It provides an estimate of the running time of an algorithm.
54+
3. **Best-Case Analysis**: Best-case analysis is used to determine the minimum amount of time an algorithm will take to run on a given input. It provides a lower bound on the running time of an algorithm.
55+
56+
## Practical Examples
57+
58+
Let's look at some practical examples of time complexity in algorithms:
59+
60+
1. **Linear Search**: The time complexity of linear search is $ O(n) $, where $ n $ is the size of the input array. This is because the algorithm has to iterate through each element in the array to find the target element.
61+
- **Description**: Linear search is a simple search algorithm that searches for a target element in an array by iterating through each element in the array.
62+
- **Time Complexity**: $ O(n) $
63+
- **Space Complexity**: $ O(1) $
64+
- **Best Case**: $ O(1) $ (when the target element is found at the first position)
65+
- **Worst Case**: $ O(n) $ (when the target element is found at the last position or not found at all)
66+
- **Average Case**: $ O(n/2) = O(n) $ (when the target element is found in the middle of the array)
67+
68+
2. **Binary Search**: The time complexity of binary search is $ O(\log n) $, where $ n $ is the size of the input array. This is because the algorithm divides the array in half at each step, reducing the search space by half.
69+
- **Description**: Binary search is a search algorithm that searches for a target element in a sorted array by repeatedly dividing the search interval in half.
70+
- **Time Complexity**: $ O(\log n) $
71+
- **Space Complexity**: $ O(1) $
72+
- **Best Case**: $ O(1) $ (when the target element is found at the middle position)
73+
- **Worst Case**: $ O(\log n) $ (when the target element is found at the last position or not found at all)
74+
- **Average Case**: $ O(\log n) $ (when the target element is found at any position)
75+
76+
3. **Bubble Sort**: The time complexity of bubble sort is $ O(n^2) $, where $ n $ is the size of the input array. This is because the algorithm compares adjacent elements and swaps them if they are in the wrong order, resulting in a worst-case time complexity of $ O(n^2) $.
77+
- **Description**: Bubble sort is a simple sorting algorithm that repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order.
78+
- **Time Complexity**: $ O(n^2) $
79+
- **Space Complexity**: $ O(1) $
80+
- **Best Case**: $ O(n) $ (when the input array is already sorted)
81+
- **Worst Case**: $ O(n^2) $ (when the input array is sorted in reverse order)
82+
- **Average Case**: $ O(n^2) $ (when the input array is randomly sorted)
83+
84+
4. **Merge Sort**: The time complexity of merge sort is $ O(n \log n) $, where $ n $ is the size of the input array. This is because the algorithm divides the array in half at each step and merges the subarrays in sorted order, resulting in a time complexity of $ O(n \log n) $.
85+
- **Description**: Merge sort is a divide-and-conquer sorting algorithm that divides the input array into two halves, recursively sorts the subarrays, and merges them in sorted order.
86+
- **Time Complexity**: $ O(n \log n) $
87+
- **Space Complexity**: $ O(n) $
88+
- **Best Case**: $ O(n \log n) $ (when the input array is randomly sorted)
89+
- **Worst Case**: $ O(n \log n) $ (when the input array is sorted in reverse order)
90+
- **Average Case**: $ O(n \log n) $ (when the input array is randomly sorted)
91+
92+
:::tip Tips for Analyzing Time Complexity
93+
94+
1. **Identify Loops**: Determine the number of times each loop runs.
95+
2. **Recursive Calls**: Analyze the depth and number of recursive calls.
96+
3. **Nested Loops**: Multiply the complexities of nested loops.
97+
4. **Drop Constants**: Ignore constant factors and lower-order terms.
98+
5. **Consider Worst-Case Scenario**: Always analyze the worst-case scenario for practical purposes.
99+
100+
:::
101+
102+
## Advanced Topics
103+
104+
1. **Amortized Analysis:**
105+
- **Definition:** Analyzing the average time per operation over a sequence of operations.
106+
- **Example:** Dynamic array resizing.
107+
108+
2. **Probabilistic Analysis:**
109+
- **Definition:** Analyzing the expected time complexity considering the probability distribution of inputs.
110+
- **Example:** Randomized algorithms like Quick Sort.
111+
112+
3. **Complexity Classes:**
113+
114+
- **P:** Problems solvable in polynomial time.
115+
- **NP:** Problems verifiable in polynomial time.
116+
- **NP-Complete:** Problems to which any NP problem can be reduced in polynomial time.
117+
- **NP-Hard:** Problems as hard as NP-Complete problems, not necessarily in NP.
118+
119+
## Conclusion
120+
121+
Understanding time complexity is crucial for designing efficient algorithms and evaluating their performance.
122+
123+
---
124+
125+
<h2>Authors:</h2>
126+
127+
{['ajay-dhangar'].map(username => (
128+
<Author key={username} username={username} />
129+
))}

dsa/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ id: data-structures-and-algorithms
33
title: Data Structures and Algorithms
44
sidebar_label: Data Structures and Algorithms
55
sidebar_position: 1
6+
tags: [data-structures, algorithms, dsa, resources, books, courses, websites, blogs, youtube, podcasts, interview-preparation, competitive-programming, practice-problems, mock-interviews, interview-experiences, interview-questions, interview-tips, interview-cheat-sheets, interview-preparation-misc]
7+
description: 'A comprehensive guide to Data Structures and Algorithms (DSA) including resources, books, courses, websites, blogs, YouTube channels, podcasts, interview preparation, competitive programming, practice problems, mock interviews, interview experiences, interview questions, interview tips, interview cheat sheets, and interview preparation misc.'
68
---
79

810
> Data Structures and Algorithms are the building blocks of computer science. They are the tools you'll use to build software systems. This section is a collection of resources to help you understand and master Data Structures and Algorithms.

0 commit comments

Comments
 (0)