From 733785382c7b8ab2afc8f98cc3ca1c9979a5e17a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20M=C3=BCller?= <34514239+appgurueu@users.noreply.github.com> Date: Tue, 3 Oct 2023 12:20:48 +0200 Subject: [PATCH 1/3] Revert "Switch quicksort pivot selection strategy to random (#156)" This reverts commit 4db32785a0ccd2f34950f12f3c1d20b065f73e03. --- sorts/quick_sort.ts | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/sorts/quick_sort.ts b/sorts/quick_sort.ts index a1abd5e8..c0fd192e 100644 --- a/sorts/quick_sort.ts +++ b/sorts/quick_sort.ts @@ -10,7 +10,7 @@ export const partition = ( left: number = 0, right: number = array.length - 1 ) => { - const pivot = array[choosePivot(left,right)]; + const pivot = array[Math.floor((right + left) / 2)]; let i = left; let j = right; @@ -33,20 +33,6 @@ export const partition = ( return i; }; -/** - * @function choosePivot - * @description Chooses a pivot element randomly within the subarray. - * @param {number} left - The left index of the subarray. - * @param {number} right - The right index of the subarray. - * @returns {number} - The index of the chosen pivot element. - */ -const choosePivot = ( - left: number, - right: number -): number => { - return Math.floor(Math.random() * (right - left + 1)) + left -}; - /** * Quicksort implementation * @@ -69,7 +55,7 @@ export const QuickSort = ( array: number[], left: number = 0, right: number = array.length - 1 -): number[] => { +) => { let index; if (array.length > 1) { From eaf9bcf02a34c16e2201a8554605e2a1ce929ae5 Mon Sep 17 00:00:00 2001 From: autoprettier Date: Tue, 3 Oct 2023 10:21:03 +0000 Subject: [PATCH 2/3] Formatting filenames 73378538 --- ...ll-combinations-of-size-k.ts => all_combinations_of_size_k.ts} | 0 backtracking/{generateParentheses.ts => generateparentheses.ts} | 0 ...tions-of-size-k.test.ts => all_combinations_of_size_k.test.ts} | 0 .../{generateParentheses.test.ts => generateparentheses.test.ts} | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename backtracking/{all-combinations-of-size-k.ts => all_combinations_of_size_k.ts} (100%) rename backtracking/{generateParentheses.ts => generateparentheses.ts} (100%) rename backtracking/test/{all-combinations-of-size-k.test.ts => all_combinations_of_size_k.test.ts} (100%) rename backtracking/test/{generateParentheses.test.ts => generateparentheses.test.ts} (100%) diff --git a/backtracking/all-combinations-of-size-k.ts b/backtracking/all_combinations_of_size_k.ts similarity index 100% rename from backtracking/all-combinations-of-size-k.ts rename to backtracking/all_combinations_of_size_k.ts diff --git a/backtracking/generateParentheses.ts b/backtracking/generateparentheses.ts similarity index 100% rename from backtracking/generateParentheses.ts rename to backtracking/generateparentheses.ts diff --git a/backtracking/test/all-combinations-of-size-k.test.ts b/backtracking/test/all_combinations_of_size_k.test.ts similarity index 100% rename from backtracking/test/all-combinations-of-size-k.test.ts rename to backtracking/test/all_combinations_of_size_k.test.ts diff --git a/backtracking/test/generateParentheses.test.ts b/backtracking/test/generateparentheses.test.ts similarity index 100% rename from backtracking/test/generateParentheses.test.ts rename to backtracking/test/generateparentheses.test.ts From 0f8d49cb46374eb575894d8ad119d9b0597a4a8c Mon Sep 17 00:00:00 2001 From: autoprettier Date: Tue, 3 Oct 2023 10:21:03 +0000 Subject: [PATCH 3/3] Update DIRECTORY.md --- DIRECTORY.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index ce0e7c51..6d5326b1 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -1,4 +1,18 @@ +## Backtracking + * [All Combinations Of Size K](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/backtracking/all_combinations_of_size_k.ts) + * [Generateparentheses](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/backtracking/generateparentheses.ts) + * Test + * [All Combinations Of Size K.Test](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/backtracking/test/all_combinations_of_size_k.test.ts) + * [Generateparentheses.Test](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/backtracking/test/generateparentheses.test.ts) + +## Bit Manipulation + * [Is Power Of 2](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/bit_manipulation/is_power_of_2.ts) + * [Is Power Of 4](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/bit_manipulation/is_power_of_4.ts) + * Test + * [Is Power Of 2.Test](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/bit_manipulation/test/is_power_of_2.test.ts) + * [Is Power Of 4.Test](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/bit_manipulation/test/is_power_of_4.test.ts) + ## Ciphers * [Xor Cipher](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/ciphers/xor_cipher.ts) @@ -51,6 +65,9 @@ * [Binary Search Tree](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/data_structures/tree/binary_search_tree.ts) * Test * [Binary Search Tree.Test](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/data_structures/tree/test/binary_search_tree.test.ts) + * Tries + * [Tries.Test](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/data_structures/tries/test/tries.test.ts) + * [Tries](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/data_structures/tries/tries.ts) ## Dynamic Programming * [Knapsack](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/dynamic_programming/knapsack.ts) @@ -58,11 +75,17 @@ ## Graph * [Bellman Ford](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/graph/bellman_ford.ts) * [Dijkstra](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/graph/dijkstra.ts) + * [Floyd Warshall](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/graph/floyd_warshall.ts) + * [Johnson](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/graph/johnson.ts) * [Kruskal](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/graph/kruskal.ts) + * [Prim](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/graph/prim.ts) * Test * [Bellman Ford.Test](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/graph/test/bellman_ford.test.ts) * [Dijkstra.Test](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/graph/test/dijkstra.test.ts) + * [Floyd Warshall.Test](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/graph/test/floyd_warshall.test.ts) + * [Johnson.Test](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/graph/test/johnson.test.ts) * [Kruskal.Test](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/graph/test/kruskal.test.ts) + * [Prim.Test](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/graph/test/prim.test.ts) ## Maths * [Absolute Value](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/absolute_value.ts) @@ -104,17 +127,24 @@ * [Zellers Congruence](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/zellers_congruence.ts) ## Other + * [Is Sorted Array](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/other/is_sorted_array.ts) * [Parse Nested Brackets](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/other/parse_nested_brackets.ts) + * [Shuffle Array](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/other/shuffle_array.ts) * Test + * [Is Sorted Array.Test](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/other/test/is_sorted_array.test.ts) * [Parse Nested Brackets.Test](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/other/test/parse_nested_brackets.test.ts) + * [Shuffle Array.Test](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/other/test/shuffle_array.test.ts) ## Search * [Binary Search](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/search/binary_search.ts) * [Jump Search](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/search/jump_search.ts) * [Linear Search](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/search/linear_search.ts) + * [Sentinel Search](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/search/sentinel_search.ts) ## Sorts + * [Bogo Sort](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/sorts/bogo_sort.ts) * [Bubble Sort](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/sorts/bubble_sort.ts) + * [Counting Sort](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/sorts/counting_sort.ts) * [Cycle Sort](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/sorts/cycle_sort.ts) * [Gnome Sort](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/sorts/gnome_sort.ts) * [Insertion Sort](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/sorts/insertion_sort.ts)