Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d80a8c5

Browse files
Merge pull request #2 from AllThingsSmitty/feature_update
Updates for clarity
2 parents b69ed6a + 2960395 commit d80a8c5

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

‎README.md‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ console.log(isPalindrome("racecar")); // Output: true
3333
```js
3434
function binarySearch(arr, target) {
3535
let left = 0,
36-
right = arr.length - 1;
36+
right = arr.length - 1;
3737
while (left <= right) {
3838
const mid = Math.floor((left + right) / 2);
3939
if (arr[mid] === target) return mid;
@@ -46,7 +46,7 @@ function binarySearch(arr, target) {
4646
console.log(binarySearch([1, 2, 3, 4, 5], 4)); // Output: 3
4747
```
4848

49-
**Explanation**: Efficiently searches for a target in a sorted array using a divide-and-conquer approach.
49+
**Explanation**: Searches for a target in a sorted array using a divide-and-conquer approach (Time complexity: O(log n)).
5050

5151
## 4. Fibonacci Sequence (Recursive)
5252

@@ -61,7 +61,7 @@ console.log(fibonacci(6)); // Output: 8
6161

6262
**Explanation**: Generates the nth Fibonacci number recursively by summing the two preceding numbers.
6363

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.
64+
⚠️ **Note**: This approach has exponential time complexity O(2^n) and is inefficient for large inputs. Use memoization or iteration for better performance.
6565

6666
## 5. Factorial of a Number
6767

@@ -108,9 +108,7 @@ console.log(findMax([1, 2, 3, 4, 5])); // Output: 5
108108

109109
```js
110110
function mergeSortedArrays(arr1, arr2) {
111-
let merged = [],
112-
i = 0,
113-
j = 0;
111+
let merged = [], i = 0, j = 0;
114112
while (i < arr1.length && j < arr2.length) {
115113
if (arr1[i] < arr2[j]) {
116114
merged.push(arr1[i]);
@@ -126,7 +124,7 @@ function mergeSortedArrays(arr1, arr2) {
126124
console.log(mergeSortedArrays([1, 3, 5], [2, 4, 6])); // Output: [1, 2, 3, 4, 5, 6]
127125
```
128126

129-
**Explanation**: Combines two sorted arrays into one sorted array by comparing elements sequentially.
127+
**Explanation**: Merges two sorted arrays into one sorted array by comparing elements sequentially.
130128

131129
## 9. Bubble Sort
132130

@@ -145,7 +143,7 @@ function bubbleSort(arr) {
145143
console.log(bubbleSort([5, 3, 8, 4, 2])); // Output: [2, 3, 4, 5, 8]
146144
```
147145

148-
**Explanation**: Sorts an array by repeatedly swapping adjacent elements if they are in the wrong order.
146+
**Explanation**: Sorts an array by repeatedly swapping adjacent elements if they are in the wrong order (Time complexity: O(n2)).
149147

150148
## 10. Find the GCD (Greatest Common Divisor)
151149

@@ -158,4 +156,4 @@ function gcd(a, b) {
158156
console.log(gcd(48, 18)); // Output: 6
159157
```
160158

161-
**Explanation**: Uses the Euclidean algorithm to compute the greatest common divisor of two numbers.
159+
**Explanation**: Uses the Euclidean algorithm to compute the greatest common divisor of two numbers (Time complexity: O(log min(a, b))).

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /