Skip to content

Commit b69ed6a

Browse files
Merge pull request #1 from AllThingsSmitty/feature_update
Add time complexity context
2 parents e941927 + abb6cc7 commit b69ed6a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
This list showcases some of the most popular JavaScript algorithms, from simple string manipulations to classic recursive solutions and efficient searching techniques. Each snippet demonstrates a fundamental concept often encountered in coding interviews and real-world development.
44

5+
> **Note:** Popularity is based on common interview topics, educational resources, and usage in developer communities.
6+
57
## 1. Reverse a String
68

79
```js
@@ -46,7 +48,7 @@ console.log(binarySearch([1, 2, 3, 4, 5], 4)); // Output: 3
4648

4749
**Explanation**: Efficiently searches for a target in a sorted array using a divide-and-conquer approach.
4850

49-
## 4. Fibonacci Sequence
51+
## 4. Fibonacci Sequence (Recursive)
5052

5153
```js
5254
function fibonacci(n) {
@@ -59,6 +61,8 @@ console.log(fibonacci(6)); // Output: 8
5961

6062
**Explanation**: Generates the nth Fibonacci number recursively by summing the two preceding numbers.
6163

64+
⚠️ **Note**: This approach has **exponential time complexity O(2<sup>n</sup>)** and is inefficient for large inputs. Consider memoization or iteration for better performance.
65+
6266
## 5. Factorial of a Number
6367

6468
```js
@@ -82,6 +86,8 @@ function isPrime(num) {
8286
}
8387
return true;
8488
}
89+
90+
console.log(isPrime(7)); // Output: true
8591
```
8692

8793
**Explanation**: Checks if a number is prime by testing divisibility up to its square root.
@@ -152,4 +158,4 @@ function gcd(a, b) {
152158
console.log(gcd(48, 18)); // Output: 6
153159
```
154160

155-
**Explanation:** Uses the Euclidean algorithm to compute the greatest common divisor of two numbers.
161+
**Explanation**: Uses the Euclidean algorithm to compute the greatest common divisor of two numbers.

0 commit comments

Comments
 (0)