Block swap algorithms

This article provides insufficient context for those unfamiliar with the subject. Please help improve the article by providing more context for the reader. (July 2019) (Learn how and when to remove this template message)

|

In computer algorithms, block swap algorithms swap two regions of elements of an array. It is simple to swap two non-overlapping regions of an array of equal size. However, it is not as simple to swap two contiguous regions of an array of unequal sizes (algorithms that perform such swapping are called rotation algorithms). A few well-known algorithms can accomplish this: Bentley's juggling (also known as the dolphin algorithm[1]), Gries-Mills rotation[1], triple reversal algorithm, conjoined triple reversal algorithm (also known as the trinity rotation) and Successive rotation.[1][2]

## Triple reversal algorithm

The triple reversal algorithm is the simplest to explain, using rotations. A rotation is an in-place reversal of array elements. This method swaps two elements of an array from outside in within a range. The rotation works for an even or odd number of array elements. The reversal algorithm uses three in-place rotations to accomplish an in-place block swap:

* Rotate region A
* Rotate region B
* Rotate region AB

Where A and B are adjacent regions of an array that together form the region AB.

Gries-Mills and reversal algorithms perform better than Bentley's juggling, because of their cache-friendly memory access pattern behavior.

The triple reversal algorithm parallelizes well, because rotations can be split into sub-regions, which can be rotated independently of others.

## References

1. ↑ 1.0 1.1 1.2 D. Gries, H. Mills (1981), Swapping Sections
2. ↑ Jon Bentley, "Programming Pearls", pp. 13–15, 209-211.

0.00

(0 votes)

Original source: https://en.wikipedia.org/wiki/Block swap algorithms. Read more

|

Retrieved from "https://handwiki.org/wiki/index.php?title=Block_swap_algorithms&oldid=4229304"