Skip to content

Commit 04d556a

Browse files
authored
Write space and time complexity chapter (#114)
* Create file structure for the complexity chapter Signed-off-by: starvader13 <[email protected]> * write introduction to complexity chapter Signed-off-by: starvader13 <[email protected]> --------- Signed-off-by: starvader13 <[email protected]>
1 parent 8fdcd59 commit 04d556a

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

β€Žen/complexity/README.mdβ€Ž

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
layout: editorial
3+
chapter: 8
4+
pageNumber: 53
5+
description: Analyzing an algorithm's efiiciency is most important part of writing an optimal program. This chapter deep dives into analayzing the efficiency by understanding the space and time complexity.
6+
---
7+
8+
# Chapter 8
9+
# Complexity
10+
11+
From previous chapter you should have understood how to create an algorithm. In this chapter, we will explore the intricacies of algorithmic complexity in JavaScript.
12+
13+
When designing an algorithm, it's not merely about achieving the right output; it's about attaining that result efficiently. Given that multiple algorithms can address a single problem, it's imperative to seek the most efficient solution. In computer science, the efficiency of an algorithm can be analyzed in two primary dimensions: **time** and **space**.
14+
15+
Analyzing the complexity of an algorithm is a practical necessity and not just a theoretical concept. Some benefits of an optimal algorithm is faster performance, resource conservation and improved user experience.
16+
17+
Let's take an example:
18+
```javascript
19+
function printElement(arr){
20+
for (let i=0; i<arr.length; t++){
21+
console.log(arr[i])
22+
}
23+
}
24+
```
25+
26+
Time complexity of the above algorithm is: **O(n)**
27+
28+
Space complexity of the above algorithm is: **O(1)**
29+
30+
While this might seem unfamiliar to you at the moment, as you progress through the upcoming chapters, you will begin to understand all these values more clearly.

β€Žen/complexity/space-complexity.mdβ€Ž

Whitespace-only changes.

β€Žen/complexity/time-complexity.mdβ€Ž

Whitespace-only changes.

0 commit comments

Comments
Β (0)