  Decoherence-free subsystems have been successfully developed as a tool to
preserve fragile quantum information against noises. In this letter, we develop
a structure theory for decoherence-free subsystems. Based on it, we present an
effective algorithm to construct a set of maximal decoherence-free subsystems
in the sense that any other such subsystem is a subspace of one of them. As an
application of these techniques in quantum many body systems, we propose a
simple and numerically robust method to determine if two irreducible tensors
are repeated, a key step in deciding if they are equivalent in generating
matrix product states.
