Springer Nature is making SARS-CoV-2 and COVID-19 research free. View research | View latest news | Sign up for updates

Probabilistic analysis of a grouping algorithm

  • 74 Accesses


We study thegrouping by swapping problem, which occurs in memory compaction and in computing the exponential of a matrix. In this problem we are given a sequence ofn numbers drawn from {0,1, 2,...,m−1} with repetitions allowed; we are to rearrange them, using as few swaps of adjacent elements as possible, into an order such that all the like numbers are grouped together. It is known that this problem is NP-hard. We present a probabilistic analysis of a grouping algorithm calledMEDIAN that works by sorting the numbers in the sequence according to their median positions. Our results show that the expected behavior ofMEDIAN is within 10% of optimal and is asymptotically optimal asn/m→∞ or asn/m→0.

This is a preview of subscription content, log in to check access.


  1. [1]

    Feller, W.,An Introduction to Probability Theory and Its Applications, Vol. 1, 3rd edn., Wiley, New York, 1968.

  2. [2]

    Garey, M. R., and D. S. Johnson,Computers and Intractability: A Guide to the Theory of NP-Completeness, Freeman, San Francisco, 1979.

  3. [3]

    Howell, T. D., Grouping by swapping is NP-Complete, unpublished manuscript, 1977.

  4. [4]

    Parlett, B., A Recurrence Among the Elements of Functions of Triangular Matrices,Linear Algebra and Its Applications,14 (1976), 117–121.

  5. [5]

    Reingold, E. M., J. Nievergelt, and N. Deo,Combinatorial Algorithms: Theory and Practice, Prentice-Hall, Englewood Cliffs, NJ, 1977.

Download references

Author information

Additional information

The work of this author was supported in part by the Texas Advanced Research Program under Grant 4096.

Communicated by D. T. Lee.

Rights and permissions

Reprints and Permissions

About this article

Cite this article

Wong, D.F., Reingold, E.M. Probabilistic analysis of a grouping algorithm. Algorithmica 6, 192–206 (1991). https://doi.org/10.1007/BF01759041

Download citation

Key words

  • Probabilistic analysis of algorithms
  • Grouping by swapping
  • Memory compaction
  • Exponential of a matrix