diff --git a/CHANGELOG.md b/CHANGELOG.md index f9a385cf..c6967729 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Bug Fixes (patch) +## [1.3.9] + +### Breaking Changes (major) + +### New Features (minor) + +### Bug Fixes (patch) +- fix(book): fix table typos [commit](https://github.com/amejiarosario/dsa.js/commit/bc51a7a0c97aea9dea1afa5f8af22c0bed1382d3) + ## [1.3.8] ### Breaking Changes (major) @@ -134,7 +143,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - -[Unreleased]: https://github.com/amejiarosario/dsa.js/compare/1.3.8...HEAD +[Unreleased]: https://github.com/amejiarosario/dsa.js/compare/1.3.9...HEAD +[1.3.9]: https://github.com/amejiarosario/dsa.js/compare/1.3.8...1.3.9 [1.3.7]: https://github.com/amejiarosario/dsa.js/compare/1.3.7...1.3.8 [1.3.6]: https://github.com/amejiarosario/dsa.js/compare/1.3.6...1.3.7 [1.3.6]: https://github.com/amejiarosario/dsa.js/compare/1.3.5...1.3.6 diff --git a/book/content/part02/array-vs-list-vs-queue-vs-stack.asc b/book/content/part02/array-vs-list-vs-queue-vs-stack.asc index cbf95e7a..6d7439e7 100644 --- a/book/content/part02/array-vs-list-vs-queue-vs-stack.asc +++ b/book/content/part02/array-vs-list-vs-queue-vs-stack.asc @@ -32,10 +32,10 @@ In this part of the book, we explored the most used linear data structures such .2+.^s| Data Structure 2+^s| Searching By 3+^s| Inserting at the 3+^s| Deleting from .2+.^s| Space ^|_Index/Key_ ^|_Value_ ^|_beginning_ ^|_middle_ ^|_end_ ^|_beginning_ ^|_middle_ ^|_end_ | <> ^|O(1) ^|O(n) ^|O(n) ^|O(n) ^|O(1) ^|O(n) ^|O(n) ^|O(1) ^|O(n) -| <> ^|O(n) ^|O(n) ^|O(1) ^|O(n) ^|O(1) ^|O(1) ^|O(n) ^|*O(n)* ^|O(n) -| <> ^|O(n) ^|O(n) ^|O(1) ^|O(n) ^|O(1) ^|O(1) ^|O(n) ^|*O(1)* ^|O(n) +| <> ^|O(n) ^|O(n) ^|O(1) ^|O(n) ^|*O(n)* ^|O(1) ^|O(n) ^|*O(n)* ^|O(n) +| <> ^|O(n) ^|O(n) ^|O(1) ^|O(n) ^|*O(1)* ^|O(1) ^|O(n) ^|*O(1)* ^|O(n) | <> ^|- ^|- ^|- ^|- ^|O(1) ^|- ^|- ^|O(1) ^|O(n) -| Queue (w/array) ^|- ^|- ^|- ^|- ^|*O(n)* ^|- ^|- ^|O(1) ^|O(n) -| <> (w/list) ^|- ^|- ^|- ^|- ^|O(1) ^|- ^|- ^|O(1) ^|O(n) +| Queue (w/array) ^|- ^|- ^|- ^|- ^|O(1) ^|*O(n)* ^|- ^|- ^|O(n) +| <> (w/list) ^|- ^|- ^|- ^|- ^|O(1) ^|*O(1)* ^|- ^|- ^|O(n) |=== // end::table[] diff --git a/book/content/part04/backtracking.asc b/book/content/part04/backtracking.asc index f92819dc..aedc6a91 100644 --- a/book/content/part04/backtracking.asc +++ b/book/content/part04/backtracking.asc @@ -20,7 +20,7 @@ endif::backend-pdf[] Listing all possible solutions might sound like a brute force. However, it is not the same. -Backtracking algorithms are faster than brute force one. +Backtracking algorithms are faster because it test if a path will lead to a solution or not. .Brute Force vs. Backtracking Algorithms **** diff --git a/lab/exercises/09-backtracking/generate-parentheses.js b/lab/exercises/09-backtracking/generate-parentheses.js new file mode 100644 index 00000000..7fee361b --- /dev/null +++ b/lab/exercises/09-backtracking/generate-parentheses.js @@ -0,0 +1,28 @@ +/** + * https://leetcode.com/submissions/detail/313704254/ + * @param {number} n + * @return {string[]} + */ +function generateParenthesis(n, result = [], open = 0, close = 0, curr = '') { + if (curr.length === n * 2) { + result.push(curr); + } else { + if (open < n) { + generateParenthesis(n, result, open + 1, close, `${curr}(`); + } + if (close < n) { + generateParenthesis(n, result, open, close + 1, `${curr})`); + } + } + + return result; +} + +module.exports = generateParenthesis; + +/* +0: [""] +1: ["()"] +2: ["(())", "()()"] +3: ["((()))", "()()()", "(())()", "()(())"] +*/ diff --git a/lab/exercises/09-backtracking/generate-parentheses.spec.js b/lab/exercises/09-backtracking/generate-parentheses.spec.js new file mode 100644 index 00000000..22285d55 --- /dev/null +++ b/lab/exercises/09-backtracking/generate-parentheses.spec.js @@ -0,0 +1,27 @@ +const generateParenthesis = require('./generate-parentheses'); + +describe('Generate Parenthesis', () => { + it('should work with 0', () => { + expect(generateParenthesis(1)).toEqual(expect.arrayContaining([ + ])); + }); + + it('should work with 1', () => { + expect(generateParenthesis(1)).toEqual(expect.arrayContaining([ + '()', + ])); + }); + + it('should work with 2', () => { + expect(generateParenthesis(2)).toEqual(expect.arrayContaining([ + '(())', + '()()', + ])); + }); + + it('should work with 3', () => { + expect(generateParenthesis(3)).toEqual(expect.arrayContaining( + ['((()))', '(()())', '(())()', '()(())', '()()()'], + )); + }); +}); diff --git a/lab/exercises/09-backtracking/powerset-backtrack.js b/lab/exercises/09-backtracking/powerset-backtrack.js new file mode 120000 index 00000000..7cce8c0f --- /dev/null +++ b/lab/exercises/09-backtracking/powerset-backtrack.js @@ -0,0 +1 @@ +../01-arrays/powerset/powerset-backtrack.js \ No newline at end of file diff --git a/notes.md b/notes.md index 2f927d2b..21f8845e 100644 --- a/notes.md +++ b/notes.md @@ -22,9 +22,9 @@ git log HEAD --pretty=format:%s # example git log 1.1.0..HEAD --pretty=format:%s -git log 1.3.6..HEAD --pretty=format:"- %s [commit](https://github.com/amejiarosario/dsa.js/commit/%H)" --grep "BREAKING CHANGE:" -git log 1.3.6..HEAD --pretty=format:"- %s [commit](https://github.com/amejiarosario/dsa.js/commit/%H)" --grep "^feat.*:" -git log 1.3.6..HEAD --pretty=format:"- %s [commit](https://github.com/amejiarosario/dsa.js/commit/%H)" --grep "^fix.*:" +git log 1.3.8..HEAD --pretty=format:"- %s [commit](https://github.com/amejiarosario/dsa.js/commit/%H)" --grep "BREAKING CHANGE:" +git log 1.3.8..HEAD --pretty=format:"- %s [commit](https://github.com/amejiarosario/dsa.js/commit/%H)" --grep "^feat.*:" +git log 1.3.8..HEAD --pretty=format:"- %s [commit](https://github.com/amejiarosario/dsa.js/commit/%H)" --grep "^fix.*:" ``` New features in this release @@ -117,4 +117,3 @@ alert('foo'); console.log('bar'); /* eslint-enable no-alert */ ``` - diff --git a/package.json b/package.json index f812f907..c1fc41e0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dsa.js", - "version": "1.3.8", + "version": "1.3.9", "description": "Data Structures & Algorithms in JS", "author": "Adrian Mejia (https://adrianmejia.com)", "homepage": "https://github.com/amejiarosario/dsa.js",