From 296039543e01399b3288f6c10dd31f5089b7d37a Mon Sep 17 00:00:00 2001 From: Matt Smith Date: Fri, 16 May 2025 18:51:03 -0400 Subject: [PATCH] Updates for clarity --- README.md | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 160db18..5d45187 100644 --- a/README.md +++ b/README.md @@ -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; @@ -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) @@ -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(2n)** 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 @@ -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]); @@ -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 @@ -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) @@ -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))).