Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix/sam findings#98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
amejiarosario merged 4 commits intomasterfromfix/sam-findings
Dec 22, 2020
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletionbook/content/part02/hash-map.asc
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -486,7 +486,7 @@ function longestSubstring(s) {
.Examples
[source, javascript]
----
longestSubstring('abcdaefg'); //4 ('abcd' or 'aefg')
longestSubstring('abcdaefg'); //7 ('bcdaefg')
longestSubstring('abbaa'); // 2 ('ab')
longestSubstring('abbadvdf') // 4 ('badv')
----
Expand Down
13 changes: 8 additions & 5 deletionsbook/content/part03/binary-search-tree.asc
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -52,11 +52,14 @@ With the methods `add` and `remove`, we have to guarantee that our tree always h
===== Inserting new elements in a BST

.For inserting an element in a BST, we have two scenarios:
1. If the tree is empty (root element is null), we add the newly created node as root, and that's it!
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`.
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.

For instance, let’s say that we want to insert the values 19, 21, 10, 2, 8 in a BST:
. If the tree is empty (root element is null), we add the newly created node as root, and that's it!
. If the tree has a root, compare the new value with the root. Then we have three possibilities:
.. `root == newValue`: we increase the duplicity counter in that case, and done!
.. `root > newValue`, we search on the left side of the root.
.. `root < newValue`, we search on the right side of the root.
. Repeat the comparison between the current node and `newValue`, until we find the value or (null) space.

For instance, let’s say that we want to insert the values 19, 21, 10, 2, 18 in a BST:

.Inserting values on a BST.
image::image36.png[image,width=528,height=329]
Expand Down
4 changes: 2 additions & 2 deletionsbook/content/part03/graph.asc
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -297,8 +297,8 @@ include::{codedir}/data-structures/graphs/node.js[tag=removeAdjacent, indent=0]
.2+.^s| Data Structure 2+^s| Vertices 2+^s| Edges .2+^.^s| Space Complexity
^|_Add_ ^|_Remove_ ^|_Add_ ^|_Remove_
| Graph (adj. matrix) ^| O(\|V\|^2^) ^| O(\|V\|^2^) ^|O(1) ^|O(1) ^|O(\|V\|^2^)
| Graph (adj. list w/array) ^| O(1) ^| O(\|V\| + \|E\|)) ^|O(1) ^|O(\|V\| + \|E\|) ^|O(\|V\| + \|E\|)
| Graph (adj. list w/HashSet) ^| O(1) ^| O(\|V\|)) ^|O(1) ^|O(\|V\|) ^|O(\|V\| + \|E\|)
| Graph (adj. list w/array) ^| O(1) ^| O(\|V\| + \|E\|)) ^|O(1) ^|O(\|E\|) ^|O(\|V\| + \|E\|)
| Graph (adj. list w/HashSet) ^| O(1) ^| O(\|V\|)) ^|O(1) ^|O(1) ^|O(\|V\| + \|E\|)
|===
// end::table[]

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,5 +20,11 @@ const { lenLongestSubstring } = require('./longest-substring-without-repeating-c
const expected = 5;
expect(fn(actual)).toEqual(expected);
});

it('should work with example', () => {
const actual = 'abcdaefg';
const expected = 7;
expect(fn(actual)).toEqual(expected);
});
});
});
18 changes: 10 additions & 8 deletionssrc/data-structures/graphs/graph.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,7 +41,8 @@ class Graph {
* Removes node from graph
* It also removes the reference of the deleted node from
* anywhere it was adjacent to.
* Runtime: O(|V| + |E|)
* Runtime: O(|V|) because adjacency list is implemented with a HashSet.
* It were implemented with an array then it would be O(|V| + |E|).
*@param {any} value node's value
*/
removeVertex(value){
Expand All@@ -55,9 +56,9 @@ class Graph {

// tag::addEdge[]
/**
* Create a connection between source node and destination node.
* If the graph is undirected it will also create theconneciton from destination todestination.
* If the nodesdoesn't exist then it willcreate them on the fly
* Create a connection betweenthesource node and the destination node.
* If the graph is undirected, it will also create thelink from destination tosource.
* If the nodesdon't exist, then it willmake them on the fly.
* Runtime: O(1)
*@param {any} source
*@param {any} destination
Expand All@@ -79,10 +80,11 @@ class Graph {

// tag::removeEdge[]
/**
* Remove connection between source node and destination.
* If the graph is undirected it will alsoremove theconneciton from destination todestination.
* Removetheconnection between source node and destination.
* If the graph is undirected, it will alsocreate thelink from destination tosource.
*
* Runtime: O(|E|)
* Runtime: O(1): implemented with HashSet.
* If implemented with array, would be O(|E|).
*
*@param {any} source
*@param {any} destination
Expand All@@ -105,7 +107,7 @@ class Graph {

// tag::areAdjacents[]
/**
* True if two nodes are adjacent to each other
* True if two nodes are adjacent.
*@param {any} source node's value
*@param {any} destination node's value
*/
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp