A method for realizing parity ordering of Java Exchange _java

Source: Internet
Author: User

In this paper, we illustrate the method of parity ordering for Java interchange. Share to everyone for your reference. Specifically as follows:

Odd-even ordering, or parity-changing, or brick sorting, is a relatively simple sort algorithm, originally invented for parallel computing with local interconnection. This is a sort of comparison that is similar to the bubble sort feature.

In this algorithm, an exchange is exchanged by comparing the adjacent (odd-even) position pairs in the array, if the parity is in the wrong order (the first is greater than the second). The next step repeats the operation, but for all (even-odd) position number pairs. To go on so alternately.

Sequencing of processor arrays

In a parallel calculation sort, each processor corresponds to a value and has only a local interconnect with the left and right neighbors. All processors can compare and exchange operations with neighbors at the same time, alternating in odd-even, odd-odd order. The algorithm was first published by Habermann in 1972 and shows the efficiency of parallel processing.

The algorithm can be effectively extended to cases where each processor has multiple values. In the Baudet–stevenson parity merge partitioning algorithm, each processor sorts its own array of substrings at each step, and then performs a merge partition or a transposition merge with the neighbor.

Batcher odd and even merge sort

Batcher parity merging is a related but more efficient sort algorithm, using comparison-exchange and perfect-shuffle operation.

The batcher approach is efficient on parallel computing processors with a wide range of interconnections.


Worst time complexity \theta (n^2)

The odd and even sort dynamic diagram looks like this:

Code implementation:

Package com.baobaotao.test; /** * Sorting Research */public class Sort {/** <span style= "White-space:pre" > </span> * Parity sort <span St yle= "White-space:pre" > </span> * @param array <span style= "White-space:pre" > </span> */Public 
    static void Batchersort (int[] array) {int length = Array.Length; 
    Boolean flag = true; 
      while (true) {flag = true; 
          for (int i=1;i<length-1;i+=2) {if (Array[i] > array[i+1]) {Swap (array, I, i+1); 
        Flag = false;  } for (int i=0;i<length-1;i+=2) {if (Array[i] > array[i+1]) {Swap (array, I, i+1) 
          ; 
        Flag = false; 
      } if (flag) break; 
    Printarr (array); }/** * In the order of small to large Exchange array * @param a incoming array * @param b the number of incoming to exchange B * @param c the number of incoming to exchange c * * * * public s 
    tatic void Swap (int[] A, int b, int c) {int temp = 0; if (b < c) {if (A[B] > A[c]) {temp = a[b]; 
        A[B] = A[c];  
      A[C] = temp;  /** * Print Array * @param array/public static void Printarr (int[] array) {for (int c 
    : array) {System.out.print (c + ""); 
  } System.out.println (); 
    public static void Main (string[] args) {int[] number={11,95,45,15,78,84,51,24,12}; 
  Batchersort (number); } 
}

Output Analysis:

A (
11)
12 15 24 45 51 78 84 95 (+)/A/A/A/other.

I hope this article will help you with your Java programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.