Graph Theory37 sections · 1633 units
Open in Course

Reusing the Largest Set

(Memory optimization)

Instead of creating a new set for vv, take ownership of the largest child's set. This avoids copying large sets. In C++, you can swap sets using std::swap or move them with std::move. In Python, reassign references.

After taking the big set, merge smaller sets into it element by element. Then add vv's value. The big set is now vv's set. This reuse is what makes the technique fast in practice.