|
11 | 11 | * Reference: https://www.geeksforgeeks.org/ternary-search/ |
12 | 12 | */ |
13 | 13 | /** |
14 | | - * |
| 14 | + * |
15 | 15 | * @param {number[]} arr - The sorted array to search in. |
16 | 16 | * @param {number} key - The key to search for. |
17 | 17 | * @param {number} [low=0] - The lowest index of the search range. |
18 | 18 | * @param {number} [high=arr.length - 1] - The highest index of the search range. |
19 | 19 | * @returns {number} - The index of the key if found, otherwise -1. |
20 | | - */ |
21 | | - |
| 20 | + */ |
| 21 | + |
22 | 22 | function ternarySearchRecursive(arr, key, low = 0, high = arr.length - 1) { |
23 | 23 | if (high >= low) { |
24 | 24 | // find the mid1 and mid2 |
@@ -54,13 +54,13 @@ function ternarySearchRecursive(arr, key, low = 0, high = arr.length - 1) { |
54 | 54 | return -1 |
55 | 55 | } |
56 | 56 | } |
57 | | -/** |
58 | | -* @param {number[]} arr - The sorted array to search in. |
59 | | -* @param {number} key - The key to search for. |
60 | | -* @param {number} [low=0] - The lowest index of the search range. |
61 | | -* @param {number} [high=arr.length - 1] - The highest index of the search range. |
62 | | -* @returns {number} - The index of the key if found, otherwise -1. |
63 | | -*/ |
| 57 | +/** |
| 58 | + * @param {number[]} arr - The sorted array to search in. |
| 59 | + * @param {number} key - The key to search for. |
| 60 | + * @param {number} [low=0] - The lowest index of the search range. |
| 61 | + * @param {number} [high=arr.length - 1] - The highest index of the search range. |
| 62 | + * @returns {number} - The index of the key if found, otherwise -1. |
| 63 | + */ |
64 | 64 | function ternarySearchIterative(arr, key, low = 0, high = arr.length - 1) { |
65 | 65 | while (high >= low) { |
66 | 66 | // find the mid1 and mid2 |
|
0 commit comments