A union-find algorithm performs two operations: find, which determines which subset an element belongs to, and union, which joins two subsets into a single subset. It can be used to check if an undirected graph contains cycles. A disjoint-set data structure stores a partition of a set into disjoint subsets and provides operations for adding new sets, merging sets, and finding representatives, allowing it to efficiently determine if elements are in the same or different sets. The structures are optimized using techniques like union by rank, where the shorter tree is always attached to the root of the taller tree.