Search code examples
graph-databasesmemgraphdb

BFS Algorithm in Memgraph on the karate club friendship network dataset


I want to run the Breadth-First Search (BFS) Algorithm in Python in Memgraph. How can I do that on the karate club friendship network dataset?


Solution

  • So I found out that first, you need a driver to connect to Memgraph from a Python script. The suggested way is the open-source library GQLAlchemy as it contains a lot of useful features for developing graph applications in Python.

    Once you connect with GQLAlchemy and load the dataset through Memgraph Lab, you can run the BFS algorithm using the Cypher query language.

    For example:

    results = memgraph.execute_and_fetch
    ("MATCH path=({id: "0"})-[:FRIENDS_WITH *bfs]-({id: "33"}) 
    RETURN path;")