Breadth-First Search
Breadth-first Search (BFS) is an algorithm used to explore the vertices of a graph layer by layer. It starts at the given vertex and explores all vertices at the present depth prior to moving on to the vertices at the next depth level.
Specifications
CREATE QUERY tg_bfs(SET<STRING> v_type, SET<STRING> e_type,INT max_hops=10,
VERTEX v_start, BOOL print_accum = True, STRING result_attr = "",
STRING file_path = "", BOOL display_edges = True)
Parameters
Parameter | Description | Default |
---|---|---|
|
Vertex types to traverse |
(empty string) |
|
Edge types to traverse |
(empty string) |
|
Maximum hops for the algorithm to look from each vertex |
10 |
|
Source vertex for traversal |
(empty string) |
|
Whether to print JSON output |
True |
|
The vertex attribute to store results to in |
(empty string) |
|
The path for a CSV output file |
(empty string) |
|
Whether to output edges for visualization |
False |
Example
In the example below, we run the tg_bfs
algorithm from the source vertex
alex
on the social10 graph.
RUN QUERY tg_bfs(["Person"], ["Friend"], _, ("Alex","Person"), _, _, _, _) (1)
1 | Putting _ in the position of a parameter will use the default value for that parameter. |
Below is the visualized result of the query.