-
-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from ajay-dhangar/dev-1
Dev 1
- Loading branch information
Showing
9 changed files
with
120 additions
and
57 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,16 @@ | ||
endi: | ||
name: Endilie Yacop Sucipto | ||
title: Maintainer of Docusaurus | ||
url: https://github.com/endiliey | ||
image_url: https://github.com/endiliey.png | ||
|
||
yangshun: | ||
name: Yangshun Tay | ||
title: Front End Engineer @ Facebook | ||
url: https://github.com/yangshun | ||
image_url: https://github.com/yangshun.png | ||
|
||
slorber: | ||
name: Sébastien Lorber | ||
title: Docusaurus maintainer | ||
url: https://sebastienlorber.com | ||
image_url: https://github.com/slorber.png | ||
|
||
ajay-dhangar: | ||
name: Ajay Dhangar | ||
title: Algo maintainer | ||
url: / | ||
image_url: https://github.com/ajay-dhangar.png | ||
title: Founder of CodeHarborHub | ||
url: https://ajay-dhangar.github.io/ | ||
image_url: https://avatars.githubusercontent.com/u/99037494?v=4 | ||
email: ajaydhangar49@gmail.com | ||
page: true # Turns the feature on | ||
description: > | ||
A passionate developer who loves to code and build new things. I am a Full Stack Developer and a Cyber Security, ML & AI Enthusiast. I am also a Technical Content Writer and a Speaker. I love to share my knowledge with the community. I am the Founder of CodeHarborHub. I am also a Technical Content Writer at GeeksforGeeks. I am a Girl Script Summer of Code 2024 Project Manager (PA). | ||
socials: | ||
x: CodesWithAjay | ||
linkedin: ajay-dhangar | ||
github: ajay-dhangar | ||
stackoverflow: 18530900 | ||
newsletter: https://ajay-dhangar.github.io |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
--- | ||
slug: understanding-time-space-complexity | ||
title: Understanding Time and Space Complexity in Algorithms | ||
authors: [ajay-dhangar] | ||
tags: [ajay-dhangar, algo, dsa, algorithms, time-complexity, space-complexity] | ||
--- | ||
|
||
When building efficient algorithms, one of the most crucial concepts to grasp is **Time and Space Complexity**. This concept helps us measure the performance of an algorithm in terms of the time it takes to run and the memory it consumes. | ||
|
||
<!-- truncate --> | ||
|
||
In this blog, we'll break down: | ||
|
||
- **Big O Notation**: The mathematical notation used to describe the performance of an algorithm. | ||
- **Common time complexities** like $O(1)$, $O(n)$, and $O(log n)$. | ||
- **Space complexity** and its impact on algorithm design. | ||
|
||
--- | ||
|
||
## What is Time Complexity? | ||
|
||
Time complexity is a way to describe how the runtime of an algorithm grows as the size of the input grows. It is denoted using **Big O Notation**, which describes the upper limit of an algorithm's execution time. | ||
|
||
### Common Time Complexities: | ||
|
||
1. **$O(1)$ - Constant Time:** | ||
- The algorithm's runtime is constant regardless of the input size. | ||
- Example: Accessing an element in an array by its index. | ||
|
||
2. **$O(n)$ - Linear Time:** | ||
- The algorithm's runtime grows linearly with the input size. | ||
- Example: Looping through an array of `n` elements. | ||
|
||
3. **$O(log n)$ - Logarithmic Time:** | ||
- The algorithm reduces the problem size with each step, making it very efficient for large inputs. | ||
- Example: Binary search on a sorted array. | ||
|
||
4. **$O(n^2)$ - Quadratic Time:** | ||
- The runtime grows proportionally to the square of the input size. | ||
- Example: Nested loops, such as comparing each pair of elements in a list. | ||
|
||
### Example of Time Complexity Analysis: | ||
|
||
Consider a simple loop that prints each element of an array of size `n`: | ||
|
||
```javascript title="index.js" | ||
for (let i = 0; i < n; i++) { | ||
console.log(arr[i]); | ||
} | ||
``` | ||
|
||
The time complexity of this operation is **$O(n)$** because the algorithm's runtime increases linearly with the size of the input array. | ||
|
||
--- | ||
|
||
## What is Space Complexity? | ||
|
||
Space complexity refers to the amount of memory an algorithm needs to execute relative to the input size. It includes both the space required for the input data and any additional variables or data structures the algorithm uses. | ||
|
||
### Example of Space Complexity: | ||
|
||
If an algorithm uses a constant amount of extra space, its space complexity is **$O(1)$**. On the other hand, if the algorithm requires a data structure proportional to the input size (like an extra array of size `n`), the space complexity is **$O(n)$**. | ||
|
||
### Space-Time Tradeoff: | ||
|
||
In many cases, improving time complexity might require using more memory, and vice versa. For example, **Memoization** techniques in dynamic programming optimize time at the cost of extra space. | ||
|
||
--- | ||
|
||
## Why Does This Matter? | ||
|
||
Understanding time and space complexity allows developers to make informed decisions about which algorithms to use based on the problem at hand. It's important to select algorithms that perform well, especially for large inputs. | ||
|
||
--- | ||
|
||
## Final Thoughts | ||
|
||
Analyzing the time and space complexity of algorithms is a fundamental skill for optimizing code. While Big O Notation helps in understanding the worst-case scenario, always aim to balance both time and space complexity when designing efficient algorithms. | ||
|
||
With this foundation, you're better equipped to analyze and select algorithms for your projects. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"extends": [ | ||
"config:base", | ||
"config:recommended", | ||
":dependencyDashboard" | ||
], | ||
"schedule": [ | ||
"at any time" | ||
], | ||
"packageRules": [ | ||
{ | ||
"packagePatterns": ["*"], | ||
"groupName": "all dependencies", | ||
"groupSlug": "all" | ||
} | ||
], | ||
"automerge": false, | ||
"automergeType": "pr", | ||
"prHourlyLimit": 24, | ||
"prConcurrentLimit": 10, | ||
"labels": ["dependencies"], | ||
"reviewers": ["Ajay-Dhangar"] | ||
} |