GeezerVison is showing github.com — Merge branch 'master' into master · BrandonWeb/javascript-algorithms@297875e
File treeExpand file treeCollapse file tree Open diff view settings uncategorized/knight-tour
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: README.md +3-1Lines changed: 3 additions & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -10,6 +10,8 @@ Each algorithm and data structure have its own separate README | 10 | 10 | with related explanations and links for further reading and YouTube | 11 | 11 | videos. | 12 | 12 |
| | 13 | +Read this in other languages: [Chinese](https://github.com/trekhleb/javascript-algorithms/blob/master/README.zh-CN.md) | | 14 | + | 13 | 15 | ## Data Structures | 14 | 16 |
| 15 | 17 | 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 | 190 | 192 | | **O(1)** | 1 | 1 | 1 | | 191 | 193 | | **O(log N)** | 3 | 6 | 9 | | 192 | 194 | | **O(N)** | 10 | 100 | 1000 | | 193 | | -| **O(N log N)** | 30 | 60 | 9000 | | | 195 | +| **O(N log N)** | 30 | 600 | 9000 | | 194 | 196 | | **O(N^2)** | 100 | 10000 | 1000000 | | 195 | 197 | | **O(2^N)** | 1024 | 1.26e+29 | 1.07e+301 | | 196 | 198 | | **O(N!)** | 3628800 | 9.3e+157 | 4.02e+2567 | | |
Collapse file Copy file name to clipboardExpand all lines: README.zh-CN.md +212Lines changed: 212 additions & 0 deletions - Display the source diff
- Display the rich diff
Large diffs are not rendered by default. Collapse file Copy file name to clipboardExpand all lines: src/algorithms/search/binary-search/binarySearch.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -22,7 +22,7 @@ export default function binarySearch(sortedArray, seekElement, comparatorCallbac | 22 | 22 | } | 23 | 23 |
| 24 | 24 | // 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)) { | 26 | 26 | // Go to the right half of the array. | 27 | 27 | startIndex = middleIndex + 1; | 28 | 28 | } else { | |
Collapse file Copy file name to clipboardExpand all lines: src/algorithms/sorting/bubble-sort/BubbleSort.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -18,7 +18,7 @@ export default class BubbleSort extends Sort { | 18 | 18 | this.callbacks.visitingCallback(array[j]); | 19 | 19 |
| 20 | 20 | // 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])) { | 22 | 22 | const tmp = array[j + 1]; | 23 | 23 | array[j + 1] = array[j]; | 24 | 24 | array[j] = tmp; | |
Collapse file Copy file name to clipboardExpand all lines: src/algorithms/sorting/insertion-sort/InsertionSort.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -15,7 +15,7 @@ export default class InsertionSort extends Sort { | 15 | 15 | // If this is the case then swap that elements. | 16 | 16 | while ( | 17 | 17 | array[currentIndex - 1] && | 18 | | - this.comparator.lessThen(array[currentIndex], array[currentIndex - 1]) | | 18 | + this.comparator.lessThan(array[currentIndex], array[currentIndex - 1]) | 19 | 19 | ) { | 20 | 20 | // Call visiting callback. | 21 | 21 | this.callbacks.visitingCallback(array[currentIndex - 1]); | |
Collapse file Copy file name to clipboardExpand all lines: src/algorithms/sorting/merge-sort/MergeSort.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -31,7 +31,7 @@ export default class MergeSort extends Sort { | 31 | 31 | let minimumElement = null; | 32 | 32 |
| 33 | 33 | // Find minimum element of two arrays. | 34 | | - if (this.comparator.lessThenOrEqual(leftArray[0], rightArray[0])) { | | 34 | + if (this.comparator.lessThanOrEqual(leftArray[0], rightArray[0])) { | 35 | 35 | minimumElement = leftArray.shift(); | 36 | 36 | } else { | 37 | 37 | minimumElement = rightArray.shift(); | |
Collapse file Copy file name to clipboardExpand all lines: src/algorithms/sorting/quick-sort/QuickSort.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -27,7 +27,7 @@ export default class QuickSort extends Sort { | 27 | 27 |
| 28 | 28 | if (this.comparator.equal(currentElement, pivotElement)) { | 29 | 29 | centerArray.push(currentElement); | 30 | | - } else if (this.comparator.lessThen(currentElement, pivotElement)) { | | 30 | + } else if (this.comparator.lessThan(currentElement, pivotElement)) { | 31 | 31 | leftArray.push(currentElement); | 32 | 32 | } else { | 33 | 33 | rightArray.push(currentElement); | |
Collapse file Copy file name to clipboardExpand all lines: src/algorithms/sorting/selection-sort/SelectionSort.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -16,7 +16,7 @@ export default class SelectionSort extends Sort { | 16 | 16 | // Call visiting callback. | 17 | 17 | this.callbacks.visitingCallback(array[j]); | 18 | 18 |
| 19 | | - if (this.comparator.lessThen(array[j], array[minIndex])) { | | 19 | + if (this.comparator.lessThan(array[j], array[minIndex])) { | 20 | 20 | minIndex = j; | 21 | 21 | } | 22 | 22 | } | |
Collapse file Copy file name to clipboardExpand all lines: src/algorithms/sorting/shell-sort/ShellSort.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -20,7 +20,7 @@ export default class ShellSort extends Sort { | 20 | 20 | this.callbacks.visitingCallback(array[currentIndex]); | 21 | 21 |
| 22 | 22 | // 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])) { | 24 | 24 | const tmp = array[currentIndex]; | 25 | 25 | array[currentIndex] = array[gapShiftedIndex]; | 26 | 26 | array[gapShiftedIndex] = tmp; | |
Collapse file Copy file name to clipboardExpand all lines: src/algorithms/uncategorized/knight-tour/knightTour.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 4 | 4 | * @return {number[][]} | 5 | 5 | */ | 6 | 6 | 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). | 8 | 8 | const possibleMoves = [ | 9 | 9 | [position[0] - 1, position[1] - 2], | 10 | 10 | [position[0] - 2, position[1] - 1], | |
|