Faster Treewidth-Based Approximations for Wiener Index

Authors Giovanna Kobus Conrado , Amir Kafshdar Goharshady , Pavel Hudec , Pingjiang Li , Harshit Jitendra Motwani

Thumbnail PDF


  • Filesize: 2.7 MB
  • 19 pages

Document Identifiers

Author Details

Giovanna Kobus Conrado
  • Hong Kong University of Science and Technology (HKUST), Clear Water Bay, New Territories, Hong Kong
Amir Kafshdar Goharshady
  • Hong Kong University of Science and Technology (HKUST), Clear Water Bay, New Territories, Hong Kong
Pavel Hudec
  • Hong Kong University of Science and Technology (HKUST), Clear Water Bay, New Territories, Hong Kong
Pingjiang Li
  • Hong Kong University of Science and Technology (HKUST), Clear Water Bay, New Territories, Hong Kong
Harshit Jitendra Motwani
  • Department of Computer Science and Engineering & Department of Mathematics, Hong Kong University of Science and Technology (HKUST), Clear Water Bay, New Territories, Hong Kong


Authors are ordered alphabetically.

Cite AsGet BibTex

Giovanna Kobus Conrado, Amir Kafshdar Goharshady, Pavel Hudec, Pingjiang Li, and Harshit Jitendra Motwani. Faster Treewidth-Based Approximations for Wiener Index. In 22nd International Symposium on Experimental Algorithms (SEA 2024). Leibniz International Proceedings in Informatics (LIPIcs), Volume 301, pp. 6:1-6:19, Schloss Dagstuhl – Leibniz-Zentrum für Informatik (2024)


The Wiener index of a graph G is the sum of distances between all pairs of its vertices. It is a widely-used graph property in chemistry, initially introduced to examine the link between boiling points and structural properties of alkanes, which later found notable applications in drug design. Thus, computing or approximating the Wiener index of molecular graphs, i.e. graphs in which every vertex models an atom of a molecule and every edge models a bond, is of significant interest to the computational chemistry community. In this work, we build upon the observation that molecular graphs are sparse and tree-like and focus on developing efficient algorithms parameterized by treewidth to approximate the Wiener index. We present a new randomized approximation algorithm using a combination of tree decompositions and centroid decompositions. Our algorithm approximates the Wiener index within any desired multiplicative factor (1 ± ε) in time O(n ⋅ log n ⋅ k³ + √n ⋅ k/ε²), where n is the number of vertices of the graph and k is the treewidth. This time bound is almost-linear in n. Finally, we provide experimental results over standard benchmark molecules from PubChem and the Protein Data Bank, showcasing the applicability and scalability of our approach on real-world chemical graphs and comparing it with previous methods.

Subject Classification

ACM Subject Classification
  • Theory of computation → Parameterized complexity and exact algorithms
  • Computational Chemistry
  • Treewidth
  • Wiener Index


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


  1. Ittai Abraham, Daniel Delling, Andrew V. Goldberg, and Renato Fonseca F. Werneck. A hub-based labeling algorithm for shortest paths in road networks. In SEA, volume 6630, pages 230-241, 2011. Google Scholar
  2. Ali Ahmadi, Krishnendu Chatterjee, Amir Kafshdar Goharshady, Tobias Meggendorfer, Roodabeh Safavi, and Ðorde Zikelic. Algorithms and hardness results for computing cores of markov chains. In FSTTCS, volume 250, pages 29:1-29:20, 2022. Google Scholar
  3. Ali Ahmadi, Majid Daliri, Amir Kafshdar Goharshady, and Andreas Pavlogiannis. Efficient approximations for cache-conscious data placement. In PLDI, pages 857-871, 2022. Google Scholar
  4. Tatsuya Akutsu and Hiroshi Nagamochi. Comparison and enumeration of chemical graphs. Computational and structural biotechnology journal, 5(6):e201302004, 2013. Google Scholar
  5. Ali Asadi, Krishnendu Chatterjee, Amir Kafshdar Goharshady, Kiarash Mohammadi, and Andreas Pavlogiannis. Faster algorithms for quantitative analysis of mcs and mdps with small treewidth. In ATVA, pages 253-270, 2020. Google Scholar
  6. Reinhard Bauer, Tobias Columbus, Ignaz Rutter, and Dorothea Wagner. Search-space size in contraction hierarchies. Theor. Comput. Sci., 645:112-127, 2016. Google Scholar
  7. Hans L. Bodlaender. Dynamic programming on graphs with bounded treewidth. In ICALP, volume 317, pages 105-118, 1988. Google Scholar
  8. Hans L. Bodlaender. A linear-time algorithm for finding tree-decompositions of small treewidth. SIAM J. Comput., 25(6):1305-1317, 1996. Google Scholar
  9. Hans L Bodlaender et al. A tourist guide through treewidth, 1992. Google Scholar
  10. Danail Bonchev. Chemical graph theory: introduction and fundamentals, volume 1. CRC Press, 1991. Google Scholar
  11. Gerth Stølting Brodal, Rolf Fagerberg, Christian N. S. Pedersen, and Anna Östlin. The complexity of constructing evolutionary trees using experiments. In ICALP, volume 2076, pages 140-151, 2001. Google Scholar
  12. Sergio Cabello and Christian Knauer. Algorithms for graphs of bounded treewidth via orthogonal range searching. Computational Geometry, 42(9):815-824, 2009. Google Scholar
  13. Krishnendu Chatterjee, Amir Kafshdar Goharshady, and Ehsan Kafshdar Goharshady. The treewidth of smart contracts. In SAC, pages 400-408, 2019. Google Scholar
  14. Krishnendu Chatterjee, Amir Kafshdar Goharshady, Prateesh Goyal, Rasmus Ibsen-Jensen, and Andreas Pavlogiannis. Faster algorithms for dynamic algebraic queries in basic rsms with constant treewidth. ACM Trans. Program. Lang. Syst., 41(4):23:1-23:46, 2019. Google Scholar
  15. Krishnendu Chatterjee, Amir Kafshdar Goharshady, Rasmus Ibsen-Jensen, and Andreas Pavlogiannis. Algorithms for algebraic path properties in concurrent systems of constant treewidth components. In POPL, pages 733-747, 2016. Google Scholar
  16. Krishnendu Chatterjee, Amir Kafshdar Goharshady, Rasmus Ibsen-Jensen, and Andreas Pavlogiannis. Optimal and perfectly parallel algorithms for on-demand data-flow analysis. In ESOP, volume 12075, pages 112-140, 2020. Google Scholar
  17. Krishnendu Chatterjee, Amir Kafshdar Goharshady, Nastaran Okati, and Andreas Pavlogiannis. Efficient parameterized algorithms for data packing. Proc. ACM Program. Lang., 3(POPL):53:1-53:28, 2019. Google Scholar
  18. Krishnendu Chatterjee, Amir Kafshdar Goharshady, and Andreas Pavlogiannis. JTDec: A tool for tree decompositions in soot. In ATVA, pages 59-66, 2017. Google Scholar
  19. Krishnendu Chatterjee, Rasmus Ibsen-Jensen, Amir Kafshdar Goharshady, and Andreas Pavlogiannis. Algorithms for algebraic path properties in concurrent systems of constant treewidth components. ACM Trans. Program. Lang. Syst., 40(3):9:1-9:43, 2018. Google Scholar
  20. Krishnendu Chatterjee, Rasmus Ibsen-Jensen, and Andreas Pavlogiannis. Optimal tree-decomposition balancing and reachability on low treewidth graphs, 2014. Google Scholar
  21. Shiva Chaudhuri and Christos D Zaroliagis. Shortest paths in digraphs of small treewidth. part i: Sequential algorithms. Algorithmica, 27:212-226, 2000. Google Scholar
  22. Victor Chepoi and Sandi Klavžar. The wiener index and the szeged index of benzenoid systems in linear time. Journal of chemical information and computer sciences, 37(4):752-755, 1997. Google Scholar
  23. Giovanna K Conrado, Amir K Goharshady, Harshit J Motwani, and Sergei Novozhilov. Parameterized algorithms for topological indices in chemistry. arXiv preprint arXiv:2303.13279, 2023. Google Scholar
  24. Giovanna Kobus Conrado, Amir Kafshdar Goharshady, Kerim Kochekov, Yun Chen Tsai, and Ahmed Khaled Zaher. Exploiting the sparseness of control-flow and call graphs for efficient and on-demand algebraic program analysis. Proc. ACM Program. Lang., 7(OOPSLA2):1993-2022, 2023. Google Scholar
  25. Giovanna Kobus Conrado, Amir Kafshdar Goharshady, and Chun Kit Lam. The bounded pathwidth of control-flow graphs. Proc. ACM Program. Lang., 7(OOPSLA2):292-317, 2023. Google Scholar
  26. Marek Cygan, Fedor V Fomin, Łukasz Kowalik, Daniel Lokshtanov, Dániel Marx, Marcin Pilipczuk, Michał Pilipczuk, and Saket Saurabh. Parameterized algorithms. Springer, 2015. Google Scholar
  27. Davide della Giustina, Nicola Prezza, and Rossano Venturini. A new linear-time algorithm for centroid decomposition. In SPIRE, pages 274-282, 2019. Google Scholar
  28. E Dijkstra. A note on two problems in connexion with graphs. Numerische Mathematik, 1:269-271, 1959. Google Scholar
  29. Andrey A Dobrynin, Ivan Gutman, Sandi Klavžar, and Petra Žigert. Wiener index of hexagonal systems. Acta Applicandae Mathematica, 72:247-294, 2002. Google Scholar
  30. Alexander G Dossetter, Edward J Griffen, and Andrew G Leach. Matched molecular pair analysis in drug discovery. Drug Discovery Today, 18(15-16):724-731, 2013. Google Scholar
  31. Roger C Entringer, Douglas E Jackson, and DA Snyder. Distance in graphs. Czechoslovak Mathematical Journal, 26(2):283-296, 1976. Google Scholar
  32. Ernesto Estrada and Eugenio Uriarte. Recent advances on the role of topological indices in drug discovery research. Current Medicinal Chemistry, 8(13):1573-1588, 2001. Google Scholar
  33. Robert W Floyd. Algorithm 97: shortest path. Communications of the ACM, 5(6):345, 1962. Google Scholar
  34. National Center for Biotechnology Information. Pubchem database. URL:
  35. Harold N. Gabow and Robert Endre Tarjan. A linear-time algorithm for a special case of disjoint set union. In STOC, pages 246-251, 1983. Google Scholar
  36. Amir Kafshdar Goharshady. Parameterized and Algebro-geometric Advances in Static Program Analysis. PhD thesis, Institute of Science and Technology Austria, Klosterneuburg, Austria, 2020. Google Scholar
  37. Amir Kafshdar Goharshady, Mohammad Reza Hooshmandasl, and M. Alambardar Meybodi. [1, 2]-sets and [1, 2]-total sets in trees with algorithms. Discret. Appl. Math., 198:136-146, 2016. Google Scholar
  38. Amir Kafshdar Goharshady and Fatemeh Mohammadi. An efficient algorithm for computing network reliability in small treewidth. Reliab. Eng. Syst. Saf., 193:106665, 2020. Google Scholar
  39. Amir Kafshdar Goharshady and Ahmed Khaled Zaher. Efficient interprocedural data-flow analysis using treedepth and treewidth. In VMCAI, volume 13881, pages 177-202, 2023. Google Scholar
  40. Oded Goldreich and Dana Ron. Approximating average parameters of graphs. Random Structures & Algorithms, 32(4):473-493, 2008. Google Scholar
  41. Siddharth Gupta, Adrian Kosowski, and Laurent Viennot. Exploiting hopsets: Improved distance oracles for graphs of constant highway dimension and beyond. In ICALP, volume 132, pages 143:1-143:15, 2019. Google Scholar
  42. Aric Hagberg, Pieter Swart, and Daniel S Chult. Exploring network structure, dynamics, and function using networkx. Technical report, Los Alamos National Lab.(LANL), Los Alamos, NM (United States), 2008. Google Scholar
  43. Rudolf Halin. S-functions for graphs. Journal of geometry, 8:171-186, 1976. Google Scholar
  44. Christoph Helma. Predictive toxicology. CRC Press, 2005. Google Scholar
  45. Camille Jordan. Sur les assemblages de lignes. Journal für die reine und angewandte Mathematik, 70:185-190, 1869. Google Scholar
  46. Peter C Kroon. pysmiles: A python library for parsing smiles strings. URL:
  47. Gregory Landrum. Rdkit: Open-source cheminformatics. URL:
  48. Jerzy Leszczynski. Handbook of computational chemistry, volume 3. Springer Science & Business Media, 2012. Google Scholar
  49. Mohsen Alambardar Meybodi, Amir Kafshdar Goharshady, Mohammad Reza Hooshmandasl, and Ali Shakiba. Optimal mining: Maximizing bitcoin miners' revenues from transaction fees. In Blockchain, pages 266-273, 2022. Google Scholar
  50. Bojan Mohar and Tomaž Pisanski. How to compute the wiener index of a graph. Journal of mathematical chemistry, 2(3):267-277, 1988. Google Scholar
  51. Edward F Moore. The shortest path through a maze. In Proc. of the International Symposium on the Theory of Switching, pages 285-292, 1959. Google Scholar
  52. Jaroslav Nešetřil and Patrice Ossona De Mendez. Structural properties of sparse graphs. In Building Bridges: Between Mathematics and Computer Science, pages 369-426. Springer, 2008. Google Scholar
  53. Dian Ouyang, Dong Wen, Lu Qin, Lijun Chang, Xuemin Lin, and Ying Zhang. When hierarchy meets 2-hop-labeling: efficient shortest distance and path queries on road networks. VLDB J., 32(6):1263-1287, 2023. Google Scholar
  54. RCSB. Protein data bank. URL:
  55. Neil Robertson and Paul D Seymour. Graph minors. iii. planar tree-width. Journal of Combinatorial Theory, Series B, 36(1):49-64, 1984. Google Scholar
  56. Neil Robertson and Paul D. Seymour. Graph minors. ii. algorithmic aspects of tree-width. Journal of algorithms, 7(3):309-322, 1986. Google Scholar
  57. L'ubomír Šoltés. Transmission in graphs: a bound and vertex removing. Mathematica Slovaca, 41(1):11-16, 1991. Google Scholar
  58. Ben Strasser and KIT algorithms group. Flowcutter: Software for computing flow-based balanced graph cuts. URL:
  59. Mikkel Thorup. All structured programs have small tree width and good register allocation. Information and Computation, 142(2):159-181, 1998. Google Scholar
  60. Nenad Trinajstic. Chemical graph theory. Routledge, 2018. Google Scholar
  61. Stephan Wagner and Hua Wang. Introduction to chemical graph theory. CRC Press, 2018. Google Scholar
  62. Pengfei Wan, Jianhua Tu, Shenggui Zhang, and Binlong Li. Computing the numbers of independent sets and matchings of all sizes for graphs with bounded treewidth. Applied Mathematics and Computation, 332:42-47, 2018. Google Scholar
  63. Harry Wiener. Structural determination of paraffin boiling points. Journal of the American chemical society, 69(1):17-20, 1947. Google Scholar
  64. Jun Xu and Arnold Hagler. Chemoinformatics and drug discovery. Molecules, 7(8):566-600, 2002. Google Scholar
  65. Ling Xue and Jurgen Bajorath. Molecular descriptors in chemoinformatics, computational combinatorial chemistry, and virtual screening. Combinatorial chemistry & high throughput screening, 3(5):363-372, 2000. Google Scholar
  66. Atsuko Yamaguchi, Kiyoko F Aoki, and Hiroshi Mamitsuka. Graph complexity of chemical compounds in biological pathways. Genome Informatics, 14:376-377, 2003. Google Scholar
  67. Atsuko Yamaguchi, Kiyoko F Aoki, and Hiroshi Mamitsuka. Finding the maximum common subgraph of a partial k-tree and a graph with a polynomially bounded number of spanning trees. Information Processing Letters, 92(2):57-63, 2004. Google Scholar
  68. Atsuko Yamaguchi and Kiyoko F Aoki-Kinoshita. Chemical compound complexity in biological pathways. Quantitative Graph Theory: Mathematical Foundations and Applications, page 471, 2014. Google Scholar
  69. Konrad Zuse. Der Plankalkül, 1972. Google Scholar