gcd

Tag

Cards List
#gcd

Rotation revisited: Avoiding having to calculate the gcd when doing cycle decomposition

The Old New Thing (Raymond Chen) · 2026-06-05 Cached

This article explains a technique to avoid calculating the greatest common divisor when performing cycle decomposition in std::rotate, as used in OpenJDK's Collections.rotate method. It provides a C++ implementation that tracks the count of rotated elements to determine when all cycles are complete.

0 favorites 0 likes
#gcd

Rotation revisited: Cycle decomposition in clang’s libcxx

The Old New Thing (Raymond Chen) · 2026-06-04 Cached

The article delves into the cycle decomposition algorithm used in clang's libcxx for rotation, explaining how it achieves the minimum number of swaps by computing the greatest common divisor (gcd) to determine the number of cycles.

0 favorites 0 likes
← Back to home

Submit Feedback