One Algorithm to Evaluate Them All: Unified Linear Algebra Based Approach to Evaluate Both Regular and Context-Free Path Queries

Ekaterina Shemetova, Rustam Azimov, Egor Orachev, Ilya Epelbaum, Semyon Grigorev
3/26/2021
cs.DBcs.PL

Official code: FormalLanguageConstrainedPathQuerying/CFPQ_PyAlgo (14 stars, Python, Apache-2.0, last commit 2025-12-16).

Abstract

The Kronecker product-based algorithm for context-free path querying (CFPQ) was proposed by Orachev et al. (2020). We reduce this algorithm to operations over Boolean matrices and extend it with the mechanism to extract all paths of interest.

Show full abstract

We also prove $O(n^3/\log{n})$ time complexity of the proposed algorithm, where n is a number of vertices of the input graph. Thus, we provide the alternative way to construct a slightly subcubic algorithm for CFPQ which is based on linear algebra and incremental transitive closure (a classic graph-theoretic problem), as opposed to the algorithm with the same complexity proposed by Chaudhuri (2008). Our evaluation shows that our algorithm is a good candidate to be the universal algorithm for both regular and context-free path querying.

View on arXivView PDF

Code Implementations(1)

Apache-2.0

The collection of Context-Free Path Querying algorithms

1414Python, C++Jun 23, 202011 months agoApache-2.0
context-free-grammarsgrapblaspathfinding-algorithmspython

Similar Papers

Cite this paper

@article{shemetova2021algorithm,
  title  = {One Algorithm to Evaluate Them All: Unified Linear Algebra Based Approach to Evaluate Both Regular and Context-Free Path Queries},
  author = {Ekaterina Shemetova and Rustam Azimov and Egor Orachev and Ilya Epelbaum and Semyon Grigorev},
  year   = {2021},
  eprint = {2103.14688},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2103.14688}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2103.14688.svg)](https://codeofpaper.com/paper/2103.14688)

Discussion