Determining Fixed-Length Paths in Directed and Undirected Edge-Weighted Graphs

Authors Daniel Hambly , Rhyd Lewis , Padraig Corcoran

Thumbnail PDF


  • Filesize: 0.73 MB
  • 11 pages

Document Identifiers

Author Details

Daniel Hambly
  • School of Mathematics, Cardiff University, Wales, UK
Rhyd Lewis
  • School of Mathematics, Cardiff University, Wales, UK
Padraig Corcoran
  • School of Computer Science and Informatics, Cardiff University, Wales, UK

Cite AsGet BibTex

Daniel Hambly, Rhyd Lewis, and Padraig Corcoran. Determining Fixed-Length Paths in Directed and Undirected Edge-Weighted Graphs. In 22nd International Symposium on Experimental Algorithms (SEA 2024). Leibniz International Proceedings in Informatics (LIPIcs), Volume 301, pp. 15:1-15:11, Schloss Dagstuhl – Leibniz-Zentrum für Informatik (2024)


In this paper, we examine the NP-hard problem of identifying fixed-length s-t paths in edge-weighted graphs - that is, a path of a desired length k from a source vertex s to a target vertex t. Many existing strategies look at paths whose lengths are determined by the number of edges in the path. We, however, look at the length of the path as the sum of the edge weights. Here, three exact algorithms for this problem are proposed: the first based on an integer programming (IP) formulation, the second a backtracking algorithm, and the third based on an extension of Yen’s algorithm. Analysis of these algorithms on random graphs shows that the backtracking algorithm performs best on smaller values of k, whilst the IP is preferable for larger values of k.

Subject Classification

ACM Subject Classification
  • Theory of computation → Backtracking
  • Theory of computation → Integer programming
  • Information systems → Fixed length attributes
  • Graphs
  • paths
  • backtracking
  • integer programming
  • Yen’s algorithm


  • Access Statistics
  • Total Accesses (updated on a weekly basis)
    PDF Downloads


  1. Noga Alon, Raphael Yuster, and Uri Zwick. Color-coding. J. ACM, 42(4):844-856, 1995. URL:
  2. Stefano Basagni, Danilo Bruschi, and F. Ravasio. On the difficulty of finding walks of length k. RAIRO Theor. Informatics Appl., 31(5):429-435, 1997. URL:
  3. Eric T. Bax. Algorithms to count paths and cycles. Inf. Process. Lett., 52(5):249-252, 1994. URL:
  4. Eric T. Bax and Joel Franklin. A finite-difference sieve to count paths and cycles by length. Inf. Process. Lett., 60(4):171-176, 1996. URL:
  5. Etienne Birmelé, Rui A. Ferreira, Roberto Grossi, Andrea Marino, Nadia Pisanti, Romeo Rizzi, and Gustavo Sacomoto. Optimal listing of cycles and st-paths in undirected graphs. In Sanjeev Khanna, editor, Proceedings of the Twenty-Fourth Annual ACM-SIAM Symposium on Discrete Algorithms, SODA 2013, New Orleans, Louisiana, USA, January 6-8, 2013, pages 1884-1896. SIAM, SIAM, 2013. URL:
  6. Andreas Björklund, Thore Husfeldt, Petteri Kaski, and Mikko Koivisto. The fast intersection transform with applications to counting paths. CoRR, abs/0809.2489, 2008. URL:
  7. Andreas Björklund, Thore Husfeldt, Petteri Kaski, and Mikko Koivisto. Narrow sieves for parameterized paths and packings. J. Comput. Syst. Sci., 87:119-139, 2017. URL:
  8. Hans L. Bodlaender. On linear time minor tests with depth-first search. J. Algorithms, 14(1):1-23, 1993. URL:
  9. J.A. Bondy and G. Fan. Optimal paths and cycles in weighted graphs. In Graph Theory in Memory of G.A. Dirac, volume 41 of Annals of Discrete Mathematics, pages 53-69. Elsevier, 1988. URL:
  10. David Chalupa, Phininder Balaghan, Ken A. Hawick, and Neil A. Gordon. Computational methods for finding long simple cycles in complex networks. Knowl. Based Syst., 125:96-107, 2017. URL:
  11. Jianer Chen, Joachim Kneis, Songjian Lu, Daniel Mölle, Stefan Richter, Peter Rossmanith, Sing-Hoi Sze, and Fenghui Zhang. Randomized divide-and-conquer: Improved path, matching, and packing algorithms. SIAM Journal on Computing, 38(6):2526-2547, 2009. Google Scholar
  12. Jianer Chen, Songjian Lu, Sing-Hoi Sze, and Fenghui Zhang. Improved algorithms for path, matching, and packing problems. In Nikhil Bansal, Kirk Pruhs, and Clifford Stein, editors, Proceedings of the Eighteenth Annual ACM-SIAM Symposium on Discrete Algorithms, SODA 2007, New Orleans, Louisiana, USA, January 7-9, 2007, volume 7, pages 298-307. Citeseer, SIAM, 2007. URL:
  13. Gabriel Andrew Dirac. Some theorems on abstract graphs. Proceedings of the London Mathematical Society, 3(1):69-81, 1952. Google Scholar
  14. David Eppstein. Finding the k shortest paths. SIAM J. Comput., 28(2):652-673, 1998. URL:
  15. Jörg Flum and Martin Grohe. The parameterized complexity of counting problems. SIAM J. Comput., 33(4):892-922, 2004. URL:
  16. Fedor V. Fomin, Petr A. Golovach, Tuukka Korhonen, Kirill Simonov, and Giannos Stamoulis. Fixed-parameter tractability of maximum colored path and beyond. In Nikhil Bansal and Viswanath Nagarajan, editors, Proceedings of the 2023 ACM-SIAM Symposium on Discrete Algorithms, SODA 2023, Florence, Italy, January 22-25, 2023, pages 3700-3712. SIAM, SIAM, 2023. URL:
  17. Fedor V. Fomin, Petr A. Golovach, Danil Sagunov, and Kirill Simonov. Algorithmic extensions of dirac’s theorem. In Joseph (Seffi) Naor and Niv Buchbinder, editors, Proceedings of the 2022 ACM-SIAM Symposium on Discrete Algorithms, SODA 2022, Virtual Conference / Alexandria, VA, USA, January 9 - 12, 2022, pages 406-416. SIAM, SIAM, 2022. URL:
  18. Fedor V. Fomin, Daniel Lokshtanov, Fahad Panolan, and Saket Saurabh. Efficient computation of representative families with applications in parameterized and exact algorithms. J. ACM, 63(4):29:1-29:60, 2016. URL:
  19. A. Frieze, C. McDiarmid, and B. Reed. On a conjecture of Bondy and Fan. Ars Combin., 33:329-336, 1992. Google Scholar
  20. T Gallai et al. On maximal paths and circuits of graphs. Acta Math. Acad. Sci. Hungar, 10:337-356, 1959. Google Scholar
  21. Pierre-Louis Giscard, Nils M. Kriege, and Richard C. Wilson. A general purpose algorithm for counting simple cycles and simple paths of any length. Algorithmica, 81(7):2716-2737, 2019. URL:
  22. Daniel Hambly, Rhyd Lewis, and Padraig Corcoran. Code and Data for the Paper "Determining Fixed-Length Paths in Directed and Undirected Edge-Weighted Graphs". Software, version 1.0. (visited on 2024-06-28). URL:
  23. Magnus Lie Hetland. Python Algorithms: mastering basic algorithms in the Python Language. Apress, 2014. Google Scholar
  24. Brian P Kelley, Roded Sharan, Richard M Karp, Taylor Sittler, David E Root, Brent R Stockwell, and Trey Ideker. Conserved pathways within bacteria and yeast as revealed by global protein network alignment. Proceedings of the National Academy of Sciences, 100(20):11394-11399, 2003. Google Scholar
  25. Joachim Kneis, Daniel Mölle, Stefan Richter, and Peter Rossmanith. Divide-and-color. In Fedor V. Fomin, editor, Graph-Theoretic Concepts in Computer Science, 32nd International Workshop, WG 2006, Bergen, Norway, June 22-24, 2006, Revised Papers, volume 4271 of Lecture Notes in Computer Science, pages 58-67. Springer, Springer, 2006. URL:
  26. W. Kocay and D.L. Kreher. Graphs, Algorithms, and Optimization, Second Edition. Discrete Mathematics and Its Applications. CRC Press, 2016. Google Scholar
  27. Ioannis Koutis. Faster algebraic algorithms for path and packing problems. In Luca Aceto, Ivan Damgård, Leslie Ann Goldberg, Magnús M. Halldórsson, Anna Ingólfsdóttir, and Igor Walukiewicz, editors, Automata, Languages and Programming, 35th International Colloquium, ICALP 2008, Reykjavik, Iceland, July 7-11, 2008, Proceedings, Part I: Tack A: Algorithms, Automata, Complexity, and Games, volume 5125 of Lecture Notes in Computer Science, pages 575-586. Springer, Springer, 2008. URL:
  28. Rhyd Lewis and Padraig Corcoran. Finding fixed-length circuits and cycles in undirected edge-weighted graphs: an application with street networks. J. Heuristics, 28(3):259-285, 2022. URL:
  29. Rhyd Lewis, Padraig Corcoran, and Andrei V. Gagarin. Methods for determining cycles of a specific length in undirected graphs with edge weights. J. Comb. Optim., 46(5):29, 2023. URL:
  30. Burkhard Monien. How to find long paths efficiently. In North-Holland Mathematics Studies, volume 109, pages 239-254. Elsevier, 1985. Google Scholar
  31. Sandro Montanari and Paolo Penna. On sampling simple paths in planar graphs according to their lengths. In Giuseppe F. Italiano, Giovanni Pighizzini, and Donald Sannella, editors, Mathematical Foundations of Computer Science 2015 - 40th International Symposium, MFCS 2015, Milan, Italy, August 24-28, 2015, Proceedings, Part II, volume 9235 of Lecture Notes in Computer Science, pages 493-504. Springer, Springer, 2015. URL:
  32. Christos H. Papadimitriou and Mihalis Yannakakis. On limited nondeterminism and the complexity of the V-C dimension. J. Comput. Syst. Sci., 53(2):161-170, 1996. URL:
  33. Ben Roberts and Dirk P. Kroese. Estimating the number of s-t paths in a graph. J. Graph Algorithms Appl., 11(1):195-214, 2007. URL:
  34. Jacob Scott, Trey Ideker, Richard M. Karp, and Roded Sharan. Efficient algorithms for detecting signaling pathways in protein interaction networks. J. Comput. Biol., 13(2):133-144, 2006. URL:
  35. R. Sedgewick. Algorithms in Java, Part 5: Graph Algorithms, 3rd Edition. Addison-Wesley Professional, 2003. Google Scholar
  36. Robert Sedgewick and Kevin Wayne. Algorithms, 4th Edition. Addison-Wesley, 2011. Google Scholar
  37. Dekel Tsur. Faster deterministic parameterized algorithm for k-path. Theor. Comput. Sci., 790:96-104, 2019. URL:
  38. Leslie G. Valiant. The complexity of enumeration and reliability problems. SIAM J. Comput., 8(3):410-421, 1979. URL:
  39. Piet Van Mieghem. Graph spectra for complex networks. Cambridge university press, 2023. Google Scholar
  40. David Willems, Oliver Zehner, and Stefan Ruzika. On a technique for finding running tracks of specific length in a road network. In Natalia Kliewer, Jan Fabian Ehmke, and Ralf Borndörfer, editors, Operations Research Proceedings 2017, Selected Papers of the Annual International Conference of the German Operations Research Society (GOR), Freie Universiät Berlin, Germany, September 6-8, 2017, Operations Research Proceedings, pages 333-338. Springer, Springer, 2017. URL:
  41. Ryan Williams. Finding paths of length k in o^*(2^k) time. Inf. Process. Lett., 109(6):315-318, 2009. URL:
  42. Jin Y Yen. Finding the k shortest loopless paths in a network. management Science, 17(11):712-716, 1971. Google Scholar
  43. Meirav Zehavi. Mixing color coding-related techniques. In Nikhil Bansal and Irene Finocchi, editors, Algorithms - ESA 2015 - 23rd Annual European Symposium, Patras, Greece, September 14-16, 2015, Proceedings, volume 9294 of Lecture Notes in Computer Science, pages 1037-1049. Springer, Springer, 2015. URL: