UltipaDocs
Products
Solutions
Resources
Company
Start Free Trial
UltipaDocs
Start Free Trial
  • Introduction
  • Running Algorithms
    • Degree Centrality
    • Closeness Centrality
    • Harmonic Centrality
    • Eccentricity Centrality
    • Betweenness Centrality
    • Bridges
    • Articulation Points
    • Eigenvector Centrality
    • Katz Centrality
    • CELF
    • PageRank
    • ArticleRank
    • TextRank
    • HITS
    • SybilRank
    • Jaccard Similarity
    • Overlap Similarity
    • Cosine Similarity
    • Pearson Correlation Coefficient
    • Euclidean Distance
    • KNN
    • Vector Similarity
    • Bipartite Graph
    • HyperANF
    • Weakly Connected Components (WCC)
    • Strongly Connected Components (SCC)
    • k-Edge Connected Components
    • Local Clustering Coefficient
    • Triangle Count
    • Clique Count
    • k-Core
    • k-Truss
    • p-Cohesion
    • Induced Subgraph
    • Topological Sort
    • Breadth-First Search (BFS)
    • Depth-First Search (DFS)
    • Dijkstra's Shortest Path
    • A* Shortest Path
    • Yen's K-Shortest Paths
    • Shortest Path (BFS)
    • Delta-Stepping SSSP
    • Shortest Path Faster Algorithm (SPFA)
    • All-Pairs Shortest Path (APSP)
    • Minimum Spanning Tree (MST)
    • K-Spanning Tree
    • Steiner Tree
    • Prize-Collecting Steiner Tree (PCST)
    • Minimum Cost Flow
    • Maximum Flow
    • K-Hop Fast
    • Longest Path (DAG)
    • Random Walk
    • Adamic-Adar Index
    • Common Neighbors
    • Preferential Attachment
    • Resource Allocation
    • Total Neighbors
    • Same Community
    • Louvain
    • Leiden
    • Modularity Optimization
    • Label Propagation
    • HANP
    • SLPA
    • k-Means
    • HDBSCAN
    • K-1 Coloring
    • Modularity
    • Conductance
    • Max k-Cut
      • Node2Vec
      • Struc2Vec
      • LINE
      • Fast Random Projection
      • Summary of Graph Embedding
      • Gradient Descent
      • Backpropagation
      • Skip-gram
      • Skip-gram Optimization
  1. Docs
  2. /
  3. Graph Algorithms
  4. /
  5. Pathfinding

K-Hop Fast

Overview

The K-Hop Fast algorithm counts the number of nodes reachable within a specified hop range from a given start node. It uses a bitmap-based BFS with direction-optimized traversal, designed for high performance on large graphs.

Concepts

K-Hop Neighbors

The K-hop neighbors of a node are the nodes located at a shortest distance of K from that node. The shortest distance is the number of edges in the shortest path. In graph theory, a hop is when a node travels to another node via an edge.

In this graph, nodes {B, C, D} are the 1-hop neighbors of node A, {E, F, G} are the 2-hop neighbors, and {H} is the 3-hop neighbor.

Key properties of K-hop neighbors:

  • K is determined solely by the shortest distance and is unique. For example, there may be many paths between two nodes, but K is always the shortest. A node will only appear at one hop level.
  • K-hop results are deduplicated. Even if multiple shortest paths exist to the same node, it appears only once.

Considerations

  • This algorithm requires the compute engine topology. Run ALTER GRAPH <graphName> SET COMPUTE ENABLED before using it.

Example Graph

GQL
INSERT (card1:card {_id: "card1"}), (card2:card {_id: "card2"}),
       (card3:card {_id: "card3"}), (card4:card {_id: "card4"}),
       (card5:card {_id: "card5"}), (card6:card {_id: "card6"}),
       (card7:card {_id: "card7"}), (card8:card {_id: "card8"}),
       (card1)-[:transfer]->(card2), (card2)-[:transfer]->(card3),
       (card2)-[:transfer]->(card7), (card2)-[:transfer]->(card7),
       (card3)-[:transfer]->(card4), (card4)-[:transfer]->(card3),
       (card5)-[:transfer]->(card2), (card6)-[:transfer]->(card2),
       (card7)-[:transfer]->(card3), (card8)-[:transfer]->(card3)

Parameters

NameTypeDefaultDescription
startNodeSTRING/Required. Starting node _id.
maxHopsINT3Maximum number of hops.
minHopsINT1Minimum number of hops to start counting.
directionSTRINGoutEdge direction: in, out, or both.

Run Mode

Returns:

ColumnTypeDescription
countINTTotal number of K-hop neighbors in the hop range
hopsLISTPer-hop counts as a list of integers
GQL
CALL algo.khop_fast({
  startNode: "card1",
  maxHops: 3,
  direction: "out"
}) YIELD count, hops

Result:

counthops
14

Stats Mode

Returns:

ColumnTypeDescription
countINTTotal number of K-hop neighbors
nodeCountINTTotal nodes in graph
GQL
CALL algo.khop_fast.stats({
  startNode: "card1",
  maxHops: 3,
  direction: "out"
}) YIELD count, nodeCount

Result:

countnodeCount
38