Skip to content

Exact Counting and Sampling of Labeled Graphs of Bounded Treewidth with MSO Properties

Kuncheng Zou, Yuanhong Wang, Yi Chang, Yuyi Wang, Ondřej Kuželka

cs.DS

Abstract

How many graphs on nn labeled vertices have treewidth at most kk, and how can we sample such graphs uniformly at random? We devise algorithms for both tasks that run in polynomial time for every fixed kk. Efficient counting and sampling for this class had been listed as fully open. More generally, our algorithms count and sample graphs of treewidth at most kk satisfying any property expressible in monadic second-order logic with quantification over vertex and edge sets (MSO2\mathrm{MSO}_2). This provides an algorithmic counterpart to Courcelle's theorem for counting and generating graphs subject to logical constraints. The algorithms also support vertex colors and nonnegative rational vertex and edge weights determined by colors. They compute the exact total weight of all admissible colored graphs and sample each graph with probability proportional to its weight. Let θθ comprise the treewidth bound, color set, and logical sentence, and let LL denote the encoding length of the weights. Counting uses f(θ)O(n2)f(θ)O(n^2) arithmetic operations and f(θ)poly⁡(n,L)f(θ)\operatorname{poly}(n,L) bit operations, where ff is a computable function. Generating each sample requires f(θ)poly⁡(n,L)f(θ)\operatorname{poly}(n,L) bit operations in expectation.

Create a lesson