Skip to content

Commit be813fb

Browse files
revert: "Switch quicksort pivot selection strategy to random (TheAlgorithms#172)
* Revert "Switch quicksort pivot selection strategy to random (TheAlgorithms#156)" This reverts commit 4db3278. * Formatting filenames 7337853 * Update DIRECTORY.md --------- Co-authored-by: autoprettier <[email protected]>
1 parent db5510d commit be813fb

File tree

6 files changed

+32
-16
lines changed

6 files changed

+32
-16
lines changed

DIRECTORY.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11

2+
## Backtracking
3+
* [All Combinations Of Size K](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/backtracking/all_combinations_of_size_k.ts)
4+
* [Generateparentheses](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/backtracking/generateparentheses.ts)
5+
* Test
6+
* [All Combinations Of Size K.Test](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/backtracking/test/all_combinations_of_size_k.test.ts)
7+
* [Generateparentheses.Test](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/backtracking/test/generateparentheses.test.ts)
8+
9+
## Bit Manipulation
10+
* [Is Power Of 2](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/bit_manipulation/is_power_of_2.ts)
11+
* [Is Power Of 4](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/bit_manipulation/is_power_of_4.ts)
12+
* Test
13+
* [Is Power Of 2.Test](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/bit_manipulation/test/is_power_of_2.test.ts)
14+
* [Is Power Of 4.Test](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/bit_manipulation/test/is_power_of_4.test.ts)
15+
216
## Ciphers
317
* [Xor Cipher](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/ciphers/xor_cipher.ts)
418

@@ -51,18 +65,27 @@
5165
* [Binary Search Tree](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/data_structures/tree/binary_search_tree.ts)
5266
* Test
5367
* [Binary Search Tree.Test](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/data_structures/tree/test/binary_search_tree.test.ts)
68+
* Tries
69+
* [Tries.Test](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/data_structures/tries/test/tries.test.ts)
70+
* [Tries](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/data_structures/tries/tries.ts)
5471

5572
## Dynamic Programming
5673
* [Knapsack](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/dynamic_programming/knapsack.ts)
5774

5875
## Graph
5976
* [Bellman Ford](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/graph/bellman_ford.ts)
6077
* [Dijkstra](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/graph/dijkstra.ts)
78+
* [Floyd Warshall](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/graph/floyd_warshall.ts)
79+
* [Johnson](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/graph/johnson.ts)
6180
* [Kruskal](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/graph/kruskal.ts)
81+
* [Prim](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/graph/prim.ts)
6282
* Test
6383
* [Bellman Ford.Test](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/graph/test/bellman_ford.test.ts)
6484
* [Dijkstra.Test](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/graph/test/dijkstra.test.ts)
85+
* [Floyd Warshall.Test](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/graph/test/floyd_warshall.test.ts)
86+
* [Johnson.Test](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/graph/test/johnson.test.ts)
6587
* [Kruskal.Test](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/graph/test/kruskal.test.ts)
88+
* [Prim.Test](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/graph/test/prim.test.ts)
6689

6790
## Maths
6891
* [Absolute Value](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/absolute_value.ts)
@@ -104,17 +127,24 @@
104127
* [Zellers Congruence](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/zellers_congruence.ts)
105128

106129
## Other
130+
* [Is Sorted Array](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/other/is_sorted_array.ts)
107131
* [Parse Nested Brackets](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/other/parse_nested_brackets.ts)
132+
* [Shuffle Array](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/other/shuffle_array.ts)
108133
* Test
134+
* [Is Sorted Array.Test](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/other/test/is_sorted_array.test.ts)
109135
* [Parse Nested Brackets.Test](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/other/test/parse_nested_brackets.test.ts)
136+
* [Shuffle Array.Test](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/other/test/shuffle_array.test.ts)
110137

111138
## Search
112139
* [Binary Search](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/search/binary_search.ts)
113140
* [Jump Search](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/search/jump_search.ts)
114141
* [Linear Search](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/search/linear_search.ts)
142+
* [Sentinel Search](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/search/sentinel_search.ts)
115143

116144
## Sorts
145+
* [Bogo Sort](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/sorts/bogo_sort.ts)
117146
* [Bubble Sort](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/sorts/bubble_sort.ts)
147+
* [Counting Sort](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/sorts/counting_sort.ts)
118148
* [Cycle Sort](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/sorts/cycle_sort.ts)
119149
* [Gnome Sort](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/sorts/gnome_sort.ts)
120150
* [Insertion Sort](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/sorts/insertion_sort.ts)

sorts/quick_sort.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const partition = (
1010
left: number = 0,
1111
right: number = array.length - 1
1212
) => {
13-
const pivot = array[choosePivot(left,right)];
13+
const pivot = array[Math.floor((right + left) / 2)];
1414
let i = left;
1515
let j = right;
1616

@@ -33,20 +33,6 @@ export const partition = (
3333
return i;
3434
};
3535

36-
/**
37-
* @function choosePivot
38-
* @description Chooses a pivot element randomly within the subarray.
39-
* @param {number} left - The left index of the subarray.
40-
* @param {number} right - The right index of the subarray.
41-
* @returns {number} - The index of the chosen pivot element.
42-
*/
43-
const choosePivot = (
44-
left: number,
45-
right: number
46-
): number => {
47-
return Math.floor(Math.random() * (right - left + 1)) + left
48-
};
49-
5036
/**
5137
* Quicksort implementation
5238
*
@@ -69,7 +55,7 @@ export const QuickSort = (
6955
array: number[],
7056
left: number = 0,
7157
right: number = array.length - 1
72-
): number[] => {
58+
) => {
7359
let index;
7460

7561
if (array.length > 1) {

0 commit comments

Comments
 (0)