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

[pull] master from amejiarosario:master #38

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
pull merged 6 commits into lalittolani:master from amejiarosario:master
Dec 22, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix(book/graph): add comments for runtimes using hashset implementations
  • Loading branch information
amejiarosario committed Dec 22, 2020
commit c7c7947da33cb61a794e538dff55951318edc341
2 changes: 1 addition & 1 deletion book/content/part03/graph.asc
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ include::{codedir}/data-structures/graphs/node.js[tag=removeAdjacent, indent=0]
^|_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/HashSet) ^| O(1) ^| O(\|V\|)) ^|O(1) ^|O(1) ^|O(\|V\| + \|E\|)
|===
// end::table[]

Expand Down
18 changes: 10 additions & 8 deletions src/data-structures/graphs/graph.js
View file Open in desktop
Original file line number Diff line number Diff 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 the conneciton from destination to destination.
* If the nodes doesn't exist then it will create them on the fly
* Create a connection between the source node and the destination node.
* If the graph is undirected, it will also create the link from destination to source.
* If the nodes don't exist, then it will make 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 also remove the conneciton from destination to destination.
* Remove the connection between source node and destination.
* If the graph is undirected, it will also create the link from destination to source.
*
* 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

AltStyle によって変換されたページ (->オリジナル) /