Content-Length: 349561 | pFad | http://github.com/GameOfCode64/DSA-JavaScript/commit/48fd2d46042f235f2ba8b38e48fe0ac413bd3a15

B4 Day 2 Complate Learn about Big O Notation · GameOfCode64/DSA-JavaScript@48fd2d4 · GitHub
Skip to content

Commit 48fd2d4

Browse files
committed
Day 2 Complate Learn about Big O Notation
1 parent 742086a commit 48fd2d4

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

day2.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// ! Day 2 of learning DSA in Javascript
2+
3+
// Todo: Topic 1 (Big O Notation)
4+
5+
// Todo: O(n) -> ("signifies that the execution time of the algorithm grows linearly in proportion to the size of the input data(n) ") (Linear Search) (OK Time Complexity)
6+
7+
const groceryList = ["Milk", "Eggs", "Bread", "Butter", "Cheese", "Tomatoes"];
8+
9+
function findGrocery(item) {
10+
for (i = 0; i < groceryList.length; i++) {
11+
if (groceryList[i] === item) {
12+
return `found ${item}`;
13+
}
14+
}
15+
}
16+
console.log(findGrocery("Butter"));
17+
18+
// Todo: O(1) -> ("aka constant time signifies that the execution time of an algorithm remains constant regardless of the input size") (Good Time Complexity)
19+
20+
const numberList = [1, 2, 3, 4, 5, 6, 7];
21+
22+
function findNumber(array, index) {
23+
return array[index];
24+
}
25+
26+
console.log(findNumber(numberList, 6));
27+
28+
// Todo: O(n^2) -> (" O(n^2) Indicates that the algorithm's execution time grows quadratically with the size of the input data (represent by n") (Quadratic) (Bad Time Complexity)
29+
30+
function findPairs(array) {
31+
for (i = 0; i < array.length; i++) {
32+
for (j = i + 1; j < array.length; j++) {
33+
console.log(`Pair ${array[i]} ${array[j]}`);
34+
}
35+
}
36+
}
37+
const numbers = [1, 2, 3, 4, 5];
38+
console.log(findPairs(numbers));
39+
40+
// Todo: O(log n) -> ("Time Complexity refers to an algorithm's runtime that grows algorithmically with the size of the input represented by n in simple terms as the input size increase the time it take for the algorithm to run increases slowly") (Binary Search) (Good Time Complexity)
41+
42+
// Todo: O(n log n) -> ("We use in Sorting") (OK Time Complexity)
43+
44+
// Todo: O(2n) -> ("Exponential Time Complexity (use in recursion)") (Bad Time Complexity)
45+
// Todo: O(3n) -> ("Exponential Time Complexity (use in recursion)") (Bad Time Complexity)
46+
// Todo: O(4n) -> ("Exponential Time Complexity (use in recursion)") (Bad Time Complexity)
47+
48+
// Todo: O(n!) -> ("Worst Time Complexity")

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/GameOfCode64/DSA-JavaScript/commit/48fd2d46042f235f2ba8b38e48fe0ac413bd3a15

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy