Optional val: V["val"]Private Readonly _edgeProtected _edgesPrivate Readonly _vertexOptional val: V["val"]In TypeScript, a subclass inherits the interface implementation of its parent class, without needing to implement the same interface again in the subclass. This behavior differs from Java's approach. In Java, if a parent class implements an interface, the subclass needs to explicitly implement the same interface, even if the parent class has already implemented it. This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
Optional val: V["val"]Protected _setProtected _set--- start find cycles ---
The function adds an undirected edge to a graph by updating the adjacency list.
An object representing an undirected edge in a graph. It has a property called "vertices" which is an array of two vertices connected by the edge.
a boolean value.
BellmanFord time:O(VE) space:O(V)
one to rest pairs
The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all edges for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edges, the Bellman-Ford algorithm is more flexible in some scenarios.
The bellmanFord function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
all other vertices in a graph, and optionally detects negative cycles and generates the minimum path.
The src parameter is the source vertex from which the Bellman-Ford algorithm will
start calculating the shortest paths. It can be either a vertex object or a vertex ID.
Optional scanNegativeCycle: booleanA boolean flag indicating whether to scan for negative cycles in the graph.
Optional getMin: booleanThe getMin parameter is a boolean flag that determines whether the algorithm should
calculate the minimum distance from the source vertex to all other vertices in the graph. If getMin is set to
true, the algorithm will find the minimum distance and update the min variable with the minimum
Optional genPath: booleanA boolean flag indicating whether to generate paths for all vertices from the source vertex.
The function bellmanFord returns an object with the following properties:
Optional val: V["val"]The function "degreeOf" returns the degree of a given vertex in an undirected graph.
The parameter vertexOrId can be either a VertexId or an
V.
the degree of the vertex.
Dijkstra algorithm time: O(logVE) space: O(V + E)
Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
The dijkstra function implements Dijkstra's algorithm to find the shortest path between a source vertex and an
optional destination vertex, and optionally returns the minimum distance, the paths, and other information.
The src parameter represents the source vertex from which the Dijkstra algorithm will
start. It can be either a vertex object or a vertex ID.
Optional dest: null | VertexId | VThe dest parameter is the destination vertex or vertex ID. It specifies the
vertex to which the shortest path is calculated from the source vertex. If no destination is provided, the algorithm
will calculate the shortest paths to all other vertices from the source vertex.
Optional getMinDist: booleanThe getMinDist parameter is a boolean flag that determines whether the minimum
distance from the source vertex to the destination vertex should be calculated and returned in the result. If
getMinDist is set to true, the minDist property in the result will contain the minimum distance
Optional genPaths: booleanThe genPaths parameter is a boolean flag that determines whether or not to generate
paths in the Dijkstra algorithm. If genPaths is set to true, the algorithm will calculate and return the
shortest paths from the source vertex to all other vertices in the graph. If genPaths @returns The function dijkstrareturns an object of typeDijkstraResult
Dijkstra algorithm time: O(VE) space: O(V + E)
The function dijkstraWithoutHeap implements Dijkstra's algorithm to find the shortest path between two vertices in
a graph without using a heap data structure.
The source vertex from which to start the Dijkstra's algorithm. It can be either a vertex object or a vertex ID.
Optional dest: null | VertexId | VThe dest parameter in the dijkstraWithoutHeap function is an optional
parameter that specifies the destination vertex for the Dijkstra algorithm. It can be either a vertex object or its
identifier. If no destination is provided, the value is set to null.
Optional getMinDist: booleanThe getMinDist parameter is a boolean flag that determines whether the minimum
distance from the source vertex to the destination vertex should be calculated and returned in the result. If
getMinDist is set to true, the minDist property in the result will contain the minimum distance
Optional genPaths: booleanThe genPaths parameter is a boolean flag that determines whether or not to generate
paths in the Dijkstra algorithm. If genPaths is set to true, the algorithm will calculate and return the
shortest paths from the source vertex to all other vertices in the graph. If genPaths @returns The function dijkstraWithoutHeapreturns an object of typeDijkstraResult
The function "edgesOf" returns an array of undirected edges connected to a given vertex or vertex ID.
The parameter vertexOrId can be either a VertexId or an
V.
an array of UndirectedEdge objects.
Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle all pairs The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edges, and it can simultaneously compute shortest paths between any two nodes. The function implements the Floyd-Warshall algorithm to find the shortest path between all pairs of vertices in a graph.
The function floyd() returns an object with two properties: costs and predecessor. The costs
property is a 2D array of numbers representing the shortest path costs between vertices in a graph. The
predecessor property is a 2D array of vertices (or null) representing the predecessor vertices in the shortest
path between vertices in the
The function "getEdgesOf" returns an array of undirected edges connected to a given vertex or vertex ID.
The parameter vertexOrId can be either an
V object or a VertexId.
The function getEdgesOf returns an array of E objects.
The function "getEndsOfEdge" returns the two vertices that form the ends of a given undirected edge, or null if the edge does not exist in the graph.
An object representing an undirected edge in a graph. It has a property called "vertices" which is an array containing two vertices that the edge connects.
The function getEndsOfEdge returns an array containing the two ends of the given edge if the edge
exists in the graph. If the edge does not exist, it returns null.
The function getMinCostBetween calculates the minimum cost between two vertices in a graph, either based on edge
weights or using a breadth-first search algorithm.
The parameter v1 represents the starting vertex or vertex ID of the graph.
The parameter v2 represents the second vertex in the graph. It can be either a vertex
object or a vertex ID.
Optional isWeight: booleanisWeight is an optional parameter that indicates whether the graph edges have weights. If isWeight is set to true, the function will calculate the minimum cost between v1 and v2 based on the weights of the edges. If isWeight is set to false or not provided, the function will calculate the
The function getMinCostBetween returns a number representing the minimum cost between two vertices (v1
and v2) in a graph. If the isWeight parameter is true, it calculates the minimum weight between the vertices.
If isWeight is false or not provided, it calculates the minimum number of edges between the vertices. If the
vertices are not
The function getMinPathBetween returns the minimum path between two vertices in a graph, either based on weight or
using a breadth-first search algorithm.
The parameter v1 represents the starting vertex or its ID.
The parameter v2 represents the destination vertex or its ID. It is the vertex that we
want to find the minimum path to from the source vertex v1.
Optional isWeight: booleanA boolean flag indicating whether to consider the weight of edges in finding the minimum path. If set to true, the function will use Dijkstra's algorithm to find the minimum weighted path. If set to false, the function will use breadth-first search (BFS) to find the minimum path. If
The function getMinPathBetween returns an array of vertices (V[]) representing the minimum path between
two vertices (v1 and v2). If no path is found, it returns null.
The function getNeighbors returns an array of neighboring vertices of a given vertex in an undirected graph.
The vertexOrId parameter can be either an
V object or a VertexId. It represents the vertex for which we want to find the neighbors.
an array of UndirectedVertex objects.
The function checks if a vertex exists in a graph.
The parameter vertexOrId can accept either a vertex object (V) or a vertex ID
(VertexId).
The method hasVertex returns a boolean value.
The function removes all vertices from a graph and returns a boolean indicating if any vertices were removed.
The vertices parameter can be either an array of vertices (V[]) or an array
of vertex IDs (VertexId[]).
a boolean value. It returns true if at least one vertex was successfully removed, and false if no vertices were removed.
The removeEdge function removes an edge between two vertices in an undirected graph.
An object representing an undirected edge. It has a property called "vertices" which is an array containing the two vertices connected by the edge.
The method is returning an UndirectedEdge object or null.
The function removes an edge between two vertices in an undirected graph.
The parameter v1 represents either an V object or
a VertexId. It is used to specify one of the vertices of the edge that needs to be removed.
The parameter v2 represents either an instance of the
UndirectedVertex class or a VertexId. It is used to identify the second vertex of the edge that needs to be
removed.
The function removeEdgeBetween returns an E object if an edge is successfully removed
between the two vertices v1 and v2. If either v1 or v2 is not found in the graph, or if there is no edge
between them, the function returns null.
The removeVertex function removes a vertex from a graph by its ID or by the vertex object itself.
The parameter vertexOrId can be either a vertex object (V) or a vertex ID
(VertexId).
The method removeVertex returns a boolean value.
The function sets the weight of an edge between two vertices in a graph.
The srcOrId parameter can be either a VertexId or a V object. It represents
the source vertex of the edge.
The destOrId parameter represents the destination vertex of the edge. It can be
either a VertexId or a vertex object V.
The weight parameter represents the weight of the edge between the source vertex (srcOrId) and the destination vertex (destOrId).
a boolean value. If the edge exists between the source and destination vertices, the function will update the weight of the edge and return true. If the edge does not exist, the function will return false.
Tarjan is an algorithm based on DFS,which is used to solve the connectivity problem of graphs.
Tarjan can find cycles in directed or undirected graph
Tarjan can find the articulation points and bridges(critical edges) of undirected graphs in linear time,
Tarjan solve the bi-connected components of undirected graphs;
Tarjan can find the SSC(strongly connected components), articulation points, and bridges of directed graphs.
The tarjan function is used to perform various graph analysis tasks such as finding articulation points, bridges,
strongly connected components (SCCs), and cycles in a graph.
Optional needArticulationPoints: booleanA boolean value indicating whether or not to calculate and return the articulation points in the graph. Articulation points are the vertices in a graph whose removal would increase the number of connected components in the graph.
Optional needBridges: booleanA boolean flag indicating whether the algorithm should find and return the bridges (edges whose removal would increase the number of connected components in the graph).
Optional needSCCs: booleanA boolean value indicating whether the Strongly Connected Components (SCCs) of the graph are needed. If set to true, the function will calculate and return the SCCs of the graph. If set to false, the SCCs will not be calculated or returned.
Optional needCycles: booleanA boolean flag indicating whether the algorithm should find cycles in the graph. If set to true, the algorithm will return a map of cycles, where the keys are the low values of the SCCs and the values are arrays of vertices that form cycles within the SCCs.
The function tarjan returns an object with the following properties:
Generated using TypeDoc
In TypeScript, a subclass inherits the interface implementation of its parent class, without needing to implement the same interface again in the subclass. This behavior differs from Java's approach. In Java, if a parent class implements an interface, the subclass needs to explicitly implement the same interface, even if the parent class has already implemented it. This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.