Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ console.log(isPalindrome("racecar")); // Output: true
```js
function binarySearch(arr, target) {
let left = 0,
right = arr.length - 1;
right = arr.length - 1;
while (left <= right) {
const mid = Math.floor((left + right) / 2);
if (arr[mid] === target) return mid;
Expand All @@ -46,7 +46,7 @@ function binarySearch(arr, target) {
console.log(binarySearch([1, 2, 3, 4, 5], 4)); // Output: 3
```

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

## 4. Fibonacci Sequence (Recursive)

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

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

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

## 5. Factorial of a Number

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

```js
function mergeSortedArrays(arr1, arr2) {
let merged = [],
i = 0,
j = 0;
let merged = [], i = 0, j = 0;
while (i < arr1.length && j < arr2.length) {
if (arr1[i] < arr2[j]) {
merged.push(arr1[i]);
Expand All @@ -126,7 +124,7 @@ function mergeSortedArrays(arr1, arr2) {
console.log(mergeSortedArrays([1, 3, 5], [2, 4, 6])); // Output: [1, 2, 3, 4, 5, 6]
```

**Explanation**: Combines two sorted arrays into one sorted array by comparing elements sequentially.
**Explanation**: Merges two sorted arrays into one sorted array by comparing elements sequentially.

## 9. Bubble Sort

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

**Explanation**: Sorts an array by repeatedly swapping adjacent elements if they are in the wrong order.
**Explanation**: Sorts an array by repeatedly swapping adjacent elements if they are in the wrong order (Time complexity: O(n²)).

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

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

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