  Boson sampling is a fundamentally and practically important task that can be
used to demonstrate quantum supremacy using noisy intermediate-scale quantum
devices. In this work, we present classical sampling algorithms for
single-photon and Gaussian input states that take advantage of a graph
structure of a linear-optical circuit. The algorithms' complexity grows as
so-called treewidth, which is closely related to the connectivity of a given
linear-optical circuit. Using the algorithms, we study approximated simulations
for local Haar-random linear-optical circuits. For equally spaced initial
sources, we show that when the circuit depth is less than the quadratic in the
lattice spacing, the efficient simulation is possible with an exponentially
small error. Notably, right after this depth, photons start to interfere each
other and the algorithms' complexity becomes sub-exponential in the number of
sources, implying that there is a sharp transition of its complexity. Finally,
when a circuit is sufficiently deep enough for photons to typically propagate
to all modes, the complexity becomes exponential as generic sampling
algorithms. We numerically implement a likelihood test with a recent Gaussian
boson sampling experiment and show that the treewidth-based algorithm with a
limited treewidth renders a larger likelihood than the experimental data.
