Skip to content

Commit 9b5412f

Browse files
author
Isaac Ramírez
authored
Merge pull request #4 from iramirezc/chapter-2
Chapter 2: Sorting
2 parents d89f007 + b1f30b5 commit 9b5412f

File tree

131 files changed

+7079
-1141
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+7079
-1141
lines changed

.gitignore

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# Logs
1+
# docs output
2+
docs/html/*
3+
!docs/html/.gitkeep
4+
5+
# logs
26
logs
37
*.log
48
npm-debug.log*
@@ -7,4 +11,7 @@ yarn-error.log*
711
lerna-debug.log*
812

913
# npm modules
10-
node_modules/
14+
node_modules
15+
16+
# symlinks
17+
algs4-data

README.md

+18-23
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,6 @@
22

33
Personal notes and JavaScript code for the book Algorithms (4th edition) by Robert Sedgewick & Kevin Wayne.
44

5-
## Chapters' Notes
6-
7-
* [Chapter 1. Fundamentals](/docs/chapter-1.notes.md)
8-
* Chapter 2. Sorting
9-
* Chapter 3. Searching
10-
* Chapter 4. Graphs
11-
* Chapter 5. Strings
12-
* Chapter 6. Context
13-
145
## Standard Libraries for JavaScript
156

167
* [In](/src/libs/in/in.js)
@@ -19,13 +10,9 @@ Personal notes and JavaScript code for the book Algorithms (4th edition) by Robe
1910
* [StdOut](/src/libs/std-out/std-out.js)
2011
* [StdRandom](/src/libs/std-random/std-random.js)
2112

22-
## Benchmarks
23-
24-
* [Linear Search vs. Binary Search](/src/benchmarks/searching/linear-vs-binary-search.js)
25-
2613
## Algorithms & Data Structures
2714

28-
_For a list similar to the book site see this [algorithms list](/docs/algorithms-list.md)._
15+
_For a list similar to the book site see this [algorithms list](/markdown/algorithms.md)._
2916

3017
### Chapter 1. Fundamentals
3118

@@ -61,19 +48,27 @@ _For a list similar to the book site see this [algorithms list](/docs/algorithms
6148

6249
**Algorithms:**
6350

64-
> TODO
51+
* [Selection Sort - p. 249](/src/algorithms/selection-sort/selection-sort.js)
52+
* [Insertion Sort - p. 251](/src/algorithms/insertion-sort/insertion-sort.js)
53+
* [Shell Sort - p. 259](/src/algorithms/shell-sort/shell-sort.js)
54+
* [Merge Sort - p. 273](/src/algorithms/merge-sort/merge-sort.js)
55+
* [MergeBU Sort - p. 278](/src/algorithms/merge-sort-bu/merge-sort-bu.js)
56+
* [Quick Sort - p. 289](/src/algorithms/quick-sort/quick-sort.js)
57+
* [Quick3way Sort - p. 299](/src/algorithms/quick-3way-sort/quick-3way-sort.js)
6558

6659
**ADTs:**
6760

68-
> TODO
61+
* [MinPQ - p. 311](/src/adts/min-priority-queue/min-priority-queue.js)
62+
* [MaxPQ - p. 318](/src/adts/max-priority-queue/max-priority-queue.js)
63+
64+
**Clients:**
65+
66+
* [SortCompare - p. 256](/src/examples/test-clients/sort-compare.client.js)
6967

7068
## Exercise Solutions
7169

72-
:warning: _Do **NOT** copy any of these solutions. These are for my reference only. You should have attempted to solve any of these exercises by your own after at least a few days before even trying to look for the solution. Finally, my solutions can be wrong too._
70+
:warning: _Do **NOT** copy any of [these solutions](/src/exercises/index.md). These are for my reference only. You should have attempted to solve any of these exercises by your own after at least a few days before even trying to look for the solution. Finally, my solutions can be wrong too._
71+
72+
## Benchmarks
7373

74-
* [Chapter 1. Fundamentals](/src/exercises/index.md)
75-
* Chapter 2. Sorting
76-
* Chapter 3. Searching
77-
* Chapter 4. Graphs
78-
* Chapter 5. Strings
79-
* Chapter 6. Context
74+
* [Linear Search vs. Binary Search](/benchmarks/searching/linear-vs-binary-search.js)

src/benchmarks/searching/linear-vs-binary-search.js renamed to benchmarks/searching/linear-vs-binary-search.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const Benchmark = require('../tools/benchmark')
22
const { getSortedArray, getRandomInt } = require('../tools/data-generators')
3-
const { BinarySearch, LinearSearch } = require('../../algorithms')
3+
const { BinarySearch, LinearSearch } = require('../../src/algorithms')
44

55
class SearchingBenchmark extends Benchmark {
66
setUp ({ arraySize }) {

src/benchmarks/tools/benchmark.js renamed to benchmarks/tools/benchmark.js

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class Benchmark {
2828

2929
/**
3030
* Set up the data for the tests.
31+
* @abstract
3132
* @throws SyntaxError This function should be implemented by the client.
3233
*/
3334
setUp () {

client

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env node
2+
3+
const { sync } = require('glob')
4+
5+
const [clientName, ...args] = process.argv.slice(2)
6+
7+
const globOptions = { realpath: true, cwd: __dirname }
8+
9+
const files = sync('src/**/*.client.js', globOptions)
10+
11+
const clients = files.reduce((modules, path) => Object.assign(modules, require(path)), {})
12+
13+
if (!clients[clientName]) {
14+
throw new ReferenceError(`Client '${clientName}' not found.`)
15+
}
16+
17+
clients[clientName].main(args)

docs/chapter-1.notes.md

-94
This file was deleted.

docs/conf.json

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"plugins": [
3+
"plugins/markdown",
4+
"plugins/my-tags"
5+
],
6+
"markdown": {
7+
"tags": ["note"]
8+
},
9+
"recurseDepth": 10,
10+
"source": {
11+
"include": ["./src"],
12+
"exclude": [],
13+
"includePattern": ".+\\.js(doc|x)?$",
14+
"excludePattern": "(^|\\/|\\\\)_|.+\\.spec\\.js$"
15+
},
16+
"sourceType": "module",
17+
"opts": {
18+
"template": "./node_modules/ink-docstrap/template",
19+
"encoding": "utf8",
20+
"destination": "./docs/html",
21+
"recurse": true,
22+
"readme": "./README.md"
23+
},
24+
"tags": {
25+
"allowUnknownTags": true,
26+
"dictionaries": ["jsdoc", "closure"]
27+
},
28+
"templates": {
29+
"cleverLinks": false,
30+
"monospaceLinks": false,
31+
"default": {
32+
"outputSourceFiles": true,
33+
"staticFiles": {
34+
"include": ["./static"]
35+
},
36+
"includeDate": false,
37+
"useLongnameInNav": false
38+
},
39+
"theme": "simplex",
40+
"includeDate": false,
41+
"navType": "vertical",
42+
"inverseNav": false,
43+
"outputSourceFiles": true,
44+
"linenums": true,
45+
"sort": true
46+
}
47+
}

docs/html/.gitkeep

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The contents of this folder are auto-generated by issuing the command: yarn docs

docs/algorithms-list.md renamed to docs/markdown/algorithms.md

+23
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,26 @@ Every algorithm or ADT has a link pointing to the original Java implementation a
4444
* QuickUnionUF | [js](/src/algorithms/union-find-quick/union-find-quick.js) | [java](https://algs4.cs.princeton.edu/code/edu/princeton/cs/algs4/QuickUnionUF.java.html) |
4545
* WeightedQuickUnionUF | [js](/src/algorithms/union-find-weighted/union-find-weighted.js) | [java](https://algs4.cs.princeton.edu/code/edu/princeton/cs/algs4/WeightedQuickUnionUF.java.html) |
4646
* UF | js | [java](https://algs4.cs.princeton.edu/code/edu/princeton/cs/algs4/UF.java.html) |
47+
48+
### Chapter 2. Sorting
49+
50+
* Insertion | [js](/src/algorithms/insertion-sort/insertion-sort.js) | [java](https://algs4.cs.princeton.edu/code/edu/princeton/cs/algs4/Insertion.java.html) |
51+
* InsertionX | js | [java](https://algs4.cs.princeton.edu/code/edu/princeton/cs/algs4/InsertionX.java.html) |
52+
* BinaryInsertion | js | [java](https://algs4.cs.princeton.edu/code/edu/princeton/cs/algs4/BinaryInsertion.java.html) |
53+
* Selection | [js](/src/algorithms/selection-sort/selection-sort.js) | [java](https://algs4.cs.princeton.edu/code/edu/princeton/cs/algs4/Selection.java.html) |
54+
* Shell | [js](/src/algorithms/shell-sort/shell-sort.js) | [java](https://algs4.cs.princeton.edu/code/edu/princeton/cs/algs4/Shell.java.html) |
55+
* Merge | [js](/src/algorithms/merge-sort/merge-sort.js) | [java](https://algs4.cs.princeton.edu/code/edu/princeton/cs/algs4/Merge.java.html) |
56+
* MergeBU | [js](/src/algorithms/merge-sort-bu/merge-sort-bu.js) | [java](https://algs4.cs.princeton.edu/code/edu/princeton/cs/algs4/MergeBU.java.html) |
57+
* MergeX | js | [java](https://algs4.cs.princeton.edu/code/edu/princeton/cs/algs4/MergeX.java.html) |
58+
* Inversions | js | [java](https://algs4.cs.princeton.edu/code/edu/princeton/cs/algs4/Inversions.java.html) |
59+
* Quick | [js](/src/algorithms/quick-sort/quick-sort.js) | [java](https://algs4.cs.princeton.edu/code/edu/princeton/cs/algs4/Quick.java.html) |
60+
* Quick3way | [js](/src/algorithms/quick-3way-sort/quick-3way-sort.js) | [java](https://algs4.cs.princeton.edu/code/edu/princeton/cs/algs4/Quick3way.java.html) |
61+
* QuickX | js | [java](https://algs4.cs.princeton.edu/code/edu/princeton/cs/algs4/QuickX.java.html) |
62+
* QuickBentleyMcIlroy | js | [java](https://algs4.cs.princeton.edu/code/edu/princeton/cs/algs4/QuickBentleyMcIlroy.java.html) |
63+
* TopM | [js](/src/adts/min-priority-queue/min-priority-queue.client.js) | [java](https://algs4.cs.princeton.edu/code/edu/princeton/cs/algs4/TopM.java.html) |
64+
* MaxPQ | [js](/src/adts/max-priority-queue/max-priority-queue.js) | [java](https://algs4.cs.princeton.edu/code/edu/princeton/cs/algs4/MaxPQ.java.html) |
65+
* MinPQ | [js](/src/adts/min-priority-queue/min-priority-queue.js) | [java](https://algs4.cs.princeton.edu/code/edu/princeton/cs/algs4/MinPQ.java.html) |
66+
* IndexMinPQ | js | java |
67+
* IndexMaxPQ | js | java |
68+
* Multiway | js | java |
69+
* Heap | js | java |

docs/markdown/exercise.template.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
### [Exercise x.x.x](/samples/ex-x.x.x.js)
2+
3+
:pencil2: **Answer**
4+
5+
> your answer here
6+
7+
:memo: **Example**
8+
9+
> your example here
10+
11+
:computer: **Output**
12+
13+
```sh
14+
# your output here
15+
```
16+
17+
:warning: **Note**
18+
19+
> your notes here
20+
21+
:bar_chart: **Drawing**
22+
23+
![exercise x.x.x preview](/static/img/octocat.png "Octocat")

docs/plugins/my-tags.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
exports.defineTags = function (dictionary) {
2+
dictionary.defineTag('note', {
3+
onTagged: function (doclet, tag) {
4+
const note = `<p><em><strong>NOTE:</strong>&nbsp;${tag.text}</em></p>`
5+
6+
if (doclet.classdesc) {
7+
doclet.classdesc = `${doclet.classdesc}${note}`
8+
} else {
9+
doclet.description = `${doclet.description || ''}${note}`
10+
}
11+
}
12+
})
13+
}

docs/samples/ex-1.1.x.js

-34
This file was deleted.

0 commit comments

Comments
 (0)