Simulating a galaxy the brute way is O(n²): every star pulls every other. Barnes-Hut makes it O(n log n) by a lie you can control: build an octree, and if a distant cluster is far enough that its size-over-distance s/d < θ, replace the whole crowd with a single mass at its center of mass. Tune θ and you trade accuracy for speed. It is how galaxies get simulated at all.
The demo computes a cluster’s center of mass and applies the opening criterion s/d < θ=0.5: live demo
“Barnes-Hut is exact.” — it is an approximation controlled by θ; θ=0 recovers the exact O(n²) sum. cited
A controlled lie that makes galaxies computable. algorithm
On i-13, a 3-body cluster has COM 12.5; with s=4, d=100, s/d=0.4 < 0.5, so treat it as one: