UltipaDocs
Try Playground
  • Introduction
    • Show Algorithms
    • Install and Uninstall
    • Run Algorithms
    • Algorithm Results and Statistics
    • Degree Centrality
    • Closeness Centrality
    • Harmonic Centrality
    • Graph Centrality
    • Betweenness Centrality
    • Eigenvector Centrality
    • CELF
    • PageRank
    • ArticleRank
    • HITS
    • SybilRank
    • Jaccard Similarity
    • Overlap Similarity
    • Cosine Similarity
    • Pearson Correlation Coefficient
    • Euclidean Distance
    • K-Hop All
    • Bipartite Graph
    • HyperANF
    • Connected Component
    • Triangle Counting
    • Induced Subgraph
    • k-Core
    • k-Truss
    • p-Cohesion
    • k-Edge Connected Components
    • Local Clustering Coefficient
    • Topological Sort
    • Schema Overview
    • Dijkstra's Single-Source Shortest Path
    • Delta-Stepping Single-Source Shortest Path
    • Shortest Path Faster Algorithm (SPFA)
    • Minimum Spanning Tree
    • Breadth-First Search (BFS)
    • Depth-First Search (DFS)
    • Adamic-Adar Index
    • Common Neighbors
    • Preferential Attachment
    • Resource Allocation
    • Total Neighbors
    • Louvain
    • Leiden
    • Label Propagation
    • HANP
    • k-Means
    • kNN (k-Nearest Neighbors)
    • K-1 Coloring
    • Conductance
      • Random Walk
      • Node2Vec Walk
      • Node2Vec
      • Struc2Vec Walk
      • Struc2Vec
      • GraphSAGE
      • GraphSAGE Train
      • LINE
      • Fast Random Projection
      • Summary of Graph Embedding
      • Gradient Descent
      • Backpropagation
      • Skip-gram
      • Skip-gram Optimization
  1. Docs
  2. /
  3. Graph Analytics & Algorithms
  4. /
  5. Pathfinding

Breadth-First Seach (BFS)

✓ File Writeback ✕ Property Writeback ✕ Direct Return ✕ Stream Return ✕ Stats

Overview

Graph traversal is a search technique used to visit and explore all the nodes of a graph systematically. The primary goal of graph traversal is to uncover and examine the structure and connections of the graph. There are two common strategies for graph traversal:

  • Breadth-First Seach (BFS)
  • Depth-First Search (DFS)

The Breadth-First Search (BFS) algorithm explores a graph layer by layer and follows these steps:

  1. Create a queue (first in, first out) to keep track of visited nodes.
  2. Start from a selected node, enqueue it into the queue, and mark it as visited.
  3. Dequeue a node from the front of the queue, enqueue all its unvisited neighbors into the queue and mark them as visited.
  4. Repeat step 3 until the queue is empty.

Below is an example of traversing the graph using the BFS approach, starting from node A and assuming to visit neighbors in alphabetical order (A~Z):

Considerations

  • Only nodes that are in the same connected component as the start node can be traversed. Nodes in different connect components will not be included in the traversal results.

Syntax

  • Command: algo(traverse)
  • Parameters:
Name
Type
Spec
Default
Optional
Description
ids / uuids_id / _uuid//NoID/UUID of the start node to traverse the graph
directionstringin, out/YesDirection of edges when traversing the graph
traverse_typestringbfsbfsYesTo traverse the graph in the BFS approach, keep it as bfs

Examples

File Writeback

Spec
Content
Description
filename_id,_idThe visited node (toNode), and the node from which it is visited (fromNode)
UQL
algo(traverse).params({
  ids: ['A'],
  direction: 'out',
  traverse_type: 'bfs'
}).write({
  file: {
      filename: 'result'
  }
})

Results: File result

File
F,E
E,B
D,A
C,F
B,A
A,A