Skip to content

Commit 4350fca

Browse files
Merge pull request #98 from amejiarosario/fix/sam-findings
Fix/sam findings
2 parents 65b6edd + 436848d commit 4350fca

File tree

5 files changed

+27
-16
lines changed

5 files changed

+27
-16
lines changed

book/content/part02/hash-map.asc

+1-1
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ function longestSubstring(s) {
486486
.Examples
487487
[source, javascript]
488488
----
489-
longestSubstring('abcdaefg'); // 4 ('abcd' or 'aefg')
489+
longestSubstring('abcdaefg'); // 7 ('bcdaefg')
490490
longestSubstring('abbaa'); // 2 ('ab')
491491
longestSubstring('abbadvdf') // 4 ('badv')
492492
----

book/content/part03/binary-search-tree.asc

+8-5
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,14 @@ With the methods `add` and `remove`, we have to guarantee that our tree always h
5252
===== Inserting new elements in a BST
5353

5454
.For inserting an element in a BST, we have two scenarios:
55-
1. If the tree is empty (root element is null), we add the newly created node as root, and that's it!
56-
2. If the root is not null. Start from it and compare the node’s value against the new element. If the node has higher than a new item, we move to the right child, otherwise to the left. We check each node recursively until we find an empty spot to put the new element and keep the rule `right < parent < left`.
57-
3. If we insert the same value multiple times, we don’t want duplicates. So, we can keep track of multiples using a duplicity counter.
58-
59-
For instance, let’s say that we want to insert the values 19, 21, 10, 2, 8 in a BST:
55+
. If the tree is empty (root element is null), we add the newly created node as root, and that's it!
56+
. If the tree has a root, compare the new value with the root. Then we have three possibilities:
57+
.. `root == newValue`: we increase the duplicity counter in that case, and done!
58+
.. `root > newValue`, we search on the left side of the root.
59+
.. `root < newValue`, we search on the right side of the root.
60+
. Repeat the comparison between the current node and `newValue`, until we find the value or (null) space.
61+
62+
For instance, let’s say that we want to insert the values 19, 21, 10, 2, 18 in a BST:
6063

6164
.Inserting values on a BST.
6265
image::image36.png[image,width=528,height=329]

book/content/part03/graph.asc

+2-2
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,8 @@ include::{codedir}/data-structures/graphs/node.js[tag=removeAdjacent, indent=0]
297297
.2+.^s| Data Structure 2+^s| Vertices 2+^s| Edges .2+^.^s| Space Complexity
298298
^|_Add_ ^|_Remove_ ^|_Add_ ^|_Remove_
299299
| Graph (adj. matrix) ^| O(\|V\|^2^) ^| O(\|V\|^2^) ^|O(1) ^|O(1) ^|O(\|V\|^2^)
300-
| Graph (adj. list w/array) ^| O(1) ^| O(\|V\| + \|E\|)) ^|O(1) ^|O(\|V\| + \|E\|) ^|O(\|V\| + \|E\|)
301-
| Graph (adj. list w/HashSet) ^| O(1) ^| O(\|V\|)) ^|O(1) ^|O(\|V\|) ^|O(\|V\| + \|E\|)
300+
| Graph (adj. list w/array) ^| O(1) ^| O(\|V\| + \|E\|)) ^|O(1) ^|O(\|E\|) ^|O(\|V\| + \|E\|)
301+
| Graph (adj. list w/HashSet) ^| O(1) ^| O(\|V\|)) ^|O(1) ^|O(1) ^|O(\|V\| + \|E\|)
302302
|===
303303
// end::table[]
304304

book/interview-questions/longest-substring-without-repeating-characters.spec.js

+6
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,11 @@ const { lenLongestSubstring } = require('./longest-substring-without-repeating-c
2020
const expected = 5;
2121
expect(fn(actual)).toEqual(expected);
2222
});
23+
24+
it('should work with example', () => {
25+
const actual = 'abcdaefg';
26+
const expected = 7;
27+
expect(fn(actual)).toEqual(expected);
28+
});
2329
});
2430
});

src/data-structures/graphs/graph.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ class Graph {
4141
* Removes node from graph
4242
* It also removes the reference of the deleted node from
4343
* anywhere it was adjacent to.
44-
* Runtime: O(|V| + |E|)
44+
* Runtime: O(|V|) because adjacency list is implemented with a HashSet.
45+
* It were implemented with an array then it would be O(|V| + |E|).
4546
* @param {any} value node's value
4647
*/
4748
removeVertex(value) {
@@ -55,9 +56,9 @@ class Graph {
5556

5657
// tag::addEdge[]
5758
/**
58-
* Create a connection between source node and destination node.
59-
* If the graph is undirected it will also create the conneciton from destination to destination.
60-
* If the nodes doesn't exist then it will create them on the fly
59+
* Create a connection between the source node and the destination node.
60+
* If the graph is undirected, it will also create the link from destination to source.
61+
* If the nodes don't exist, then it will make them on the fly.
6162
* Runtime: O(1)
6263
* @param {any} source
6364
* @param {any} destination
@@ -79,10 +80,11 @@ class Graph {
7980

8081
// tag::removeEdge[]
8182
/**
82-
* Remove connection between source node and destination.
83-
* If the graph is undirected it will also remove the conneciton from destination to destination.
83+
* Remove the connection between source node and destination.
84+
* If the graph is undirected, it will also create the link from destination to source.
8485
*
85-
* Runtime: O(|E|)
86+
* Runtime: O(1): implemented with HashSet.
87+
* If implemented with array, would be O(|E|).
8688
*
8789
* @param {any} source
8890
* @param {any} destination
@@ -105,7 +107,7 @@ class Graph {
105107

106108
// tag::areAdjacents[]
107109
/**
108-
* True if two nodes are adjacent to each other
110+
* True if two nodes are adjacent.
109111
* @param {any} source node's value
110112
* @param {any} destination node's value
111113
*/

0 commit comments

Comments
 (0)