8000 Merge branch 'master' into improve-bubble-sort · yfix/javascript-algorithms@07f5ecf · GitHub
[go: up one dir, main page]

Skip to content

Commit 07f5ecf

Browse files
authored
Merge branch 'master' into improve-bubble-sort
2 parents d0ed0af + d596e1d commit 07f5ecf

File tree

13 files changed

+254
-40
lines changed

13 files changed

+254
-40
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Each algorithm and data structure have its own separate README
1010
with related explanations and links for further reading and YouTube
1111
videos.
1212

13+
Read this in other languages: [Chinese](https://github.com/trekhleb/javascript-algorithms/blob/master/README.zh-CN.md)
14+
1315
## Data Structures
1416

1517
Data structure is a particular way of organizing and storing data in a computer so that it can
@@ -190,7 +192,7 @@ Below is the list of some of the most used Big O notations and their performance
190192
| **O(1)** | 1 | 1 | 1 |
191193
| **O(log N)** | 3 | 6 | 9 |
192194
| **O(N)** | 10 | 100 | 1000 |
193-
| **O(N log N)** | 30 | 60 | 9000 |
195+
| **O(N log N)** | 30 | 600 | 9000 |
194196
| **O(N^2)** | 100 | 10000 | 1000000 |
195197
| **O(2^N)** | 1024 | 1.26e+29 | 1.07e+301 |
196198
| **O(N!)** | 3628800 | 9.3e+157 | 4.02e+2567 |

README.zh-CN.md

Lines changed: 212 additions & 0 deletions
Large diffs are not rendered by default.

src/algorithms/search/binary-search/binarySearch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default function binarySearch(sortedArray, seekElement, comparatorCallbac
2222
}
2323

2424
// Decide which half to choose for seeking next: left or right one.
25-
if (comparator.lessThen(sortedArray[middleIndex], seekElement)) {
25+
if (comparator.lessThan(sortedArray[middleIndex], seekElement)) {
2626
// Go to the right half of the array.
2727
startIndex = middleIndex + 1;
2828
} else {

src/algorithms/sorting/bubble-sort/BubbleSort.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default class BubbleSort extends Sort {
1818
this.callbacks.visitingCallback(array[j]);
1919

2020
// Swap elements if they are in wrong order.
21-
if (this.comparator.lessThen(array[j + 1], array[j])) {
21+
if (this.comparator.lessThan(array[j + 1], array[j])) {
2222
const tmp = array[j + 1];
2323
array[j + 1] = array[j];
2424
array[j] = tmp;

src/algorithms/sorting/insertion-sort/InsertionSort.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default class InsertionSort extends Sort {
1515
// If this is the case then swap that elements.
1616
while (
1717
array[currentIndex - 1] &&
18-
this.comparator.lessThen(array[currentIndex], array[currentIndex - 1])
18+
this.comparator.lessThan(array[currentIndex], array[currentIndex - 1])
1919
) {
2020
// Call visiting callback.
2121
this.callbacks.visitingCallback(array[currentIndex - 1]);

src/algorithms/sorting/merge-sort/MergeSort.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default class MergeSort extends Sort {
3131
let minimumElement = null;
3232

3333
// Find minimum element of two arrays.
34-
if (this.comparator.lessThenOrEqual(leftArray[0], rightArray[0])) {
34+
if (this.comparator.lessThanOrEqual(leftArray[0], rightArray[0])) {
3535
minimumElement = leftArray.shift();
3636
} else {
3737
minimumElement = rightArray.shift();

src/algorithms/sorting/quick-sort/QuickSort.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default class QuickSort extends Sort {
2727

2828
if (this.comparator.equal(currentElement, pivotElement)) {
2929
centerArray.push(currentElement);
30-
} else if (this.comparator.lessThen(currentElement, pivotElement)) {
30+
} else if (this.comparator.lessThan(currentElement, pivotElement)) {
3131
leftArray.push(currentElement);
3232
} else {
3333
rightArray.push(currentElement);

src/algorithms/sorting/selection-sort/SelectionSort.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default class SelectionSort extends Sort {
1616
// Call visiting callback.
1717
this.callbacks.visitingCallback(array[j]);
1818

19-
if (this.comparator.lessThen(array[j], array[minIndex])) {
19+
if (this.comparator.lessThan(array[j], array[minIndex])) {
2020
minIndex = j;
2121
}
2222
}

src/algorithms/sorting/shell-sort/ShellSort.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default class ShellSort extends Sort {
2020
this.callbacks.visitingCallback(array[currentIndex]);
2121

2222
// Compare and swap array elements if needed.
23-
if (this.comparator.lessThen(array[gapShiftedIndex], array[currentIndex])) {
23+
if (this.comparator.lessThan(array[gapShiftedIndex], array[currentIndex])) {
2424
const tmp = array[currentIndex];
2525
array[currentIndex] = array[gapShiftedIndex];
2626
array[gapShiftedIndex] = tmp;

src/algorithms/uncategorized/knight-tour/knightTour.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @return {number[][]}
55
*/
66
function getPossibleMoves(chessboard, position) {
7-
// Generate all knight moves (event those that goes beyond the board).
7+
// Generate all knight moves (even those that go beyond the board).
88
const possibleMoves = [
99
[position[0] - 1, position[1] - 2],
1010
[position[0] - 2, position[1] - 1],

0 commit comments

Comments
 (0)
0