Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3219816
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:41:24+00:00 2026-05-17T15:41:24+00:00

I’m looking for a sorting network implementation of a 5-element sort, but since I

  • 0

I’m looking for a sorting network implementation of a 5-element sort, but since I couldn’t find a good reference on SO, I’d like to ask for sorting networks for all small values of n, at least n=3 through n=6 but higher values would be great too. A good answer should at least list them as sequences of “swap” (sort on 2 elements) operations, but it might also be nice to see the recursive decomposition in terms of lower-order sorting networks.

For my application, I actually only care about the median of 5 elements, not actually putting them in order. That is, the order of the other 4 elements may be unspecified in the result as long as the median ends up in the right place. Can a sorting-networks-related approach be used to compute the median with fewer swaps than performing a full sort? If so, such a solution to my problem (for n=5) and for other cases would make a great answer too.

(Note: I’ve tagged this question C because C is the language I use and I suspect people who follow the C tag have good answers, but I don’t really care if an answer is actually written in C versus pseudo-code as long as it easily translates to C, which it should naturally do as long as the above-mentioned criteria are met.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T15:41:24+00:00Added an answer on May 17, 2026 at 3:41 pm

    Pick one from each section, presumably whichever runs fastest on your hardware since we’re firmly in the realm of “fiendish optimization”: http://smarterrecall.com/networks.html , reproduced below:

    I created this site to list all possible optimal sorting networks up to 6-inputs written using a program in matlab. The longest run-time is for 5-inputs at 45 seconds. If you are interested in contacting me, I can be reached at rpl1 [AT] rice [DOT] edu
    Cheers,
    Richard L.

    ----------
    
     - 2-input: 1 network
    
        [[1 2]]
    
    
    ----------
    
    
     - 3-input: 6 networks
    
    [[1 2][1 3][2 3]]
    [[1 2][2 3][1 2]]
    [[1 3][1 2][2 3]]
    [[1 3][2 3][1 2]]
    [[2 3][1 2][2 3]]
    [[2 3][1 3][1 2]]
    
    
    ----------
    
     - 4-input: 3 networks
    
    [[1 2][3 4][1 3][2 4][2 3]]
    [[1 3][2 4][1 2][3 4][2 3]]
    [[1 4][2 3][1 2][3 4][2 3]]
    
    
    ----------
    
     - 5-input: 180 networks
    
        [[1 2][3 4][1 3][2 5][1 2][3 4][2 3][4 5][3 4]]
        [[1 2][3 4][1 3][2 5][2 3][4 5][1 2][3 4][2 3]]
        [[1 2][3 4][1 3][4 5][1 4][2 3][2 4][3 5][3 4]]
        [[1 2][3 4][1 3][4 5][2 5][3 4][1 3][2 4][2 3]]
        [[1 2][3 4][1 4][2 5][2 3][4 5][1 2][3 4][2 3]]
        [[1 2][3 4][1 4][3 5][1 3][2 5][2 3][4 5][3 4]]
        [[1 2][3 4][1 5][2 3][1 2][4 5][2 4][3 5][3 4]]
        [[1 2][3 4][1 5][2 4][1 3][2 5][2 3][4 5][3 4]]
        [[1 2][3 4][1 5][2 4][2 3][4 5][1 2][3 4][2 3]]
        [[1 2][3 4][2 3][4 5][1 4][3 5][1 2][3 4][2 3]]
        [[1 2][3 4][2 4][3 5][1 2][4 5][1 3][2 4][2 3]]
        [[1 2][3 4][2 4][3 5][1 3][2 5][2 3][4 5][3 4]]
        [[1 2][3 5][1 3][2 4][1 2][3 5][2 3][4 5][3 4]]
        [[1 2][3 5][1 3][2 4][2 3][4 5][1 2][3 4][2 3]]
        [[1 2][3 5][1 3][4 5][1 4][2 3][2 4][3 5][3 4]]
        [[1 2][3 5][1 3][4 5][2 5][3 4][1 3][2 4][2 3]]
        [[1 2][3 5][1 4][2 3][1 2][4 5][2 4][3 5][3 4]]
        [[1 2][3 5][1 4][2 5][1 3][2 4][2 3][4 5][3 4]]
        [[1 2][3 5][1 4][2 5][2 3][4 5][1 2][3 4][2 3]]
        [[1 2][3 5][1 5][2 4][2 3][4 5][1 2][3 4][2 3]]
        [[1 2][3 5][1 5][3 4][1 3][2 4][2 3][4 5][3 4]]
        [[1 2][3 5][2 3][4 5][1 4][3 5][1 2][3 4][2 3]]
        [[1 2][3 5][2 5][3 4][1 2][4 5][1 3][2 4][2 3]]
        [[1 2][3 5][2 5][3 4][1 3][2 4][2 3][4 5][3 4]]
        [[1 2][4 5][1 3][2 4][1 2][3 5][2 3][4 5][3 4]]
        [[1 2][4 5][1 3][2 5][1 4][2 3][2 4][3 5][3 4]]
        [[1 2][4 5][1 3][2 5][2 4][3 5][1 2][3 4][2 3]]
        [[1 2][4 5][1 4][2 3][1 2][4 5][2 4][3 5][3 4]]
        [[1 2][4 5][1 4][2 3][2 4][3 5][1 2][3 4][2 3]]
        [[1 2][4 5][1 4][3 5][1 3][2 4][2 3][4 5][3 4]]
        [[1 2][4 5][1 4][3 5][2 5][3 4][1 3][2 4][2 3]]
        [[1 2][4 5][1 5][2 3][2 4][3 5][1 2][3 4][2 3]]
        [[1 2][4 5][1 5][3 4][1 3][2 4][2 3][4 5][3 4]]
        [[1 2][4 5][2 4][3 5][1 3][4 5][1 2][3 4][2 3]]
        [[1 2][4 5][2 5][3 4][1 2][4 5][1 3][2 4][2 3]]
        [[1 2][4 5][2 5][3 4][1 3][2 4][2 3][4 5][3 4]]
        [[1 3][2 4][1 2][3 5][1 3][2 4][2 3][4 5][3 4]]
        [[1 3][2 4][1 2][3 5][2 3][4 5][1 2][3 4][2 3]]
        [[1 3][2 4][1 2][4 5][1 4][2 3][2 4][3 5][3 4]]
        [[1 3][2 4][1 2][4 5][2 4][3 5][1 2][3 4][2 3]]
        [[1 3][2 4][1 4][2 5][1 2][3 5][2 3][4 5][3 4]]
        [[1 3][2 4][1 4][3 5][2 3][4 5][1 2][3 4][2 3]]
        [[1 3][2 4][1 5][2 3][1 2][4 5][2 4][3 5][3 4]]
        [[1 3][2 4][1 5][3 4][1 2][3 5][2 3][4 5][3 4]]
        [[1 3][2 4][1 5][3 4][2 3][4 5][1 2][3 4][2 3]]
        [[1 3][2 4][2 3][4 5][1 4][3 5][1 2][3 4][2 3]]
        [[1 3][2 4][2 5][3 4][1 2][3 5][2 3][4 5][3 4]]
        [[1 3][2 4][2 5][3 4][1 3][4 5][1 2][3 4][2 3]]
        [[1 3][2 5][1 2][3 4][1 3][2 5][2 3][4 5][3 4]]
        [[1 3][2 5][1 2][3 4][2 3][4 5][1 2][3 4][2 3]]
        [[1 3][2 5][1 2][4 5][1 4][2 3][2 4][3 5][3 4]]
        [[1 3][2 5][1 2][4 5][2 4][3 5][1 2][3 4][2 3]]
        [[1 3][2 5][1 4][2 3][1 2][4 5][2 4][3 5][3 4]]
        [[1 3][2 5][1 4][3 5][1 2][3 4][2 3][4 5][3 4]]
        [[1 3][2 5][1 4][3 5][2 3][4 5][1 2][3 4][2 3]]
        [[1 3][2 5][1 5][2 4][1 2][3 4][2 3][4 5][3 4]]
        [[1 3][2 5][1 5][3 4][2 3][4 5][1 2][3 4][2 3]]
        [[1 3][2 5][2 3][4 5][1 4][3 5][1 2][3 4][2 3]]
        [[1 3][2 5][2 4][3 5][1 2][3 4][2 3][4 5][3 4]]
        [[1 3][2 5][2 4][3 5][1 3][4 5][1 2][3 4][2 3]]
        [[1 3][4 5][1 2][3 4][1 3][2 5][2 3][4 5][3 4]]
        [[1 3][4 5][1 2][3 5][1 4][2 3][2 4][3 5][3 4]]
        [[1 3][4 5][1 2][3 5][2 5][3 4][1 3][2 4][2 3]]
        [[1 3][4 5][1 4][2 3][1 2][4 5][2 4][3 5][3 4]]
        [[1 3][4 5][1 4][2 3][2 4][3 5][1 2][3 4][2 3]]
        [[1 3][4 5][1 4][2 5][1 2][3 4][2 3][4 5][3 4]]
        [[1 3][4 5][1 4][2 5][2 4][3 5][1 2][3 4][2 3]]
        [[1 3][4 5][1 5][2 3][2 4][3 5][1 2][3 4][2 3]]
        [[1 3][4 5][1 5][2 4][1 2][3 4][2 3][4 5][3 4]]
        [[1 3][4 5][2 4][3 5][1 2][3 4][2 3][4 5][3 4]]
        [[1 3][4 5][2 4][3 5][1 3][4 5][1 2][3 4][2 3]]
        [[1 3][4 5][2 5][3 4][1 2][4 5][1 3][2 4][2 3]]
        [[1 4][2 3][1 2][3 5][1 3][2 4][2 3][4 5][3 4]]
        [[1 4][2 3][1 2][3 5][2 3][4 5][1 2][3 4][2 3]]
        [[1 4][2 3][1 2][4 5][1 4][2 3][2 4][3 5][3 4]]
        [[1 4][2 3][1 2][4 5][2 4][3 5][1 2][3 4][2 3]]
        [[1 4][2 3][1 3][2 5][1 2][4 5][2 4][3 5][3 4]]
        [[1 4][2 3][1 3][4 5][2 4][3 5][1 2][3 4][2 3]]
        [[1 4][2 3][1 5][2 4][1 2][3 5][2 3][4 5][3 4]]
        [[1 4][2 3][1 5][3 4][1 2][3 5][2 3][4 5][3 4]]
        [[1 4][2 3][1 5][3 4][2 3][4 5][1 2][3 4][2 3]]
        [[1 4][2 3][2 4][3 5][1 3][4 5][1 2][3 4][2 3]]
        [[1 4][2 3][2 5][3 4][1 2][3 5][2 3][4 5][3 4]]
        [[1 4][2 3][2 5][3 4][1 3][4 5][1 2][3 4][2 3]]
        [[1 4][2 5][1 2][3 4][1 3][2 5][2 3][4 5][3 4]]
        [[1 4][2 5][1 2][3 4][2 3][4 5][1 2][3 4][2 3]]
        [[1 4][2 5][1 2][3 5][1 3][2 4][2 3][4 5][3 4]]
        [[1 4][2 5][1 2][3 5][2 3][4 5][1 2][3 4][2 3]]
        [[1 4][2 5][1 3][2 4][1 2][3 5][2 3][4 5][3 4]]
        [[1 4][2 5][1 3][4 5][1 2][3 4][2 3][4 5][3 4]]
        [[1 4][2 5][1 3][4 5][2 4][3 5][1 2][3 4][2 3]]
        [[1 4][2 5][1 5][2 3][1 2][3 4][2 3][4 5][3 4]]
        [[1 4][2 5][1 5][3 4][2 3][4 5][1 2][3 4][2 3]]
        [[1 4][2 5][2 3][4 5][1 2][3 4][2 3][4 5][3 4]]
        [[1 4][2 5][2 3][4 5][1 4][3 5][1 2][3 4][2 3]]
        [[1 4][2 5][2 4][3 5][1 3][4 5][1 2][3 4][2 3]]
        [[1 4][3 5][1 2][3 4][1 3][2 5][2 3][4 5][3 4]]
        [[1 4][3 5][1 2][4 5][1 3][2 4][2 3][4 5][3 4]]
        [[1 4][3 5][1 2][4 5][2 5][3 4][1 3][2 4][2 3]]
        [[1 4][3 5][1 3][2 4][1 2][3 5][2 3][4 5][3 4]]
        [[1 4][3 5][1 3][2 4][2 3][4 5][1 2][3 4][2 3]]
        [[1 4][3 5][1 3][2 5][1 2][3 4][2 3][4 5][3 4]]
        [[1 4][3 5][1 3][2 5][2 3][4 5][1 2][3 4][2 3]]
        [[1 4][3 5][1 5][2 3][1 2][3 4][2 3][4 5][3 4]]
        [[1 4][3 5][1 5][2 4][2 3][4 5][1 2][3 4][2 3]]
        [[1 4][3 5][2 3][4 5][1 2][3 4][2 3][4 5][3 4]]
        [[1 4][3 5][2 3][4 5][1 4][3 5][1 2][3 4][2 3]]
        [[1 4][3 5][2 5][3 4][1 2][4 5][1 3][2 4][2 3]]
        [[1 5][2 3][1 2][3 4][1 3][2 5][2 3][4 5][3 4]]
        [[1 5][2 3][1 2][3 4][2 3][4 5][1 2][3 4][2 3]]
        [[1 5][2 3][1 2][4 5][1 4][2 3][2 4][3 5][3 4]]
        [[1 5][2 3][1 2][4 5][2 4][3 5][1 2][3 4][2 3]]
        [[1 5][2 3][1 3][2 4][1 2][4 5][2 4][3 5][3 4]]
        [[1 5][2 3][1 3][4 5][2 4][3 5][1 2][3 4][2 3]]
        [[1 5][2 3][1 4][2 5][1 2][3 4][2 3][4 5][3 4]]
        [[1 5][2 3][1 4][3 5][1 2][3 4][2 3][4 5][3 4]]
        [[1 5][2 3][1 4][3 5][2 3][4 5][1 2][3 4][2 3]]
        [[1 5][2 3][2 4][3 5][1 2][3 4][2 3][4 5][3 4]]
        [[1 5][2 3][2 4][3 5][1 3][4 5][1 2][3 4][2 3]]
        [[1 5][2 3][2 5][3 4][1 3][4 5][1 2][3 4][2 3]]
        [[1 5][2 4][1 2][3 4][1 3][2 5][2 3][4 5][3 4]]
        [[1 5][2 4][1 2][3 4][2 3][4 5][1 2][3 4][2 3]]
        [[1 5][2 4][1 2][3 5][1 3][2 4][2 3][4 5][3 4]]
        [[1 5][2 4][1 2][3 5][2 3][4 5][1 2][3 4][2 3]]
        [[1 5][2 4][1 3][2 5][1 2][3 4][2 3][4 5][3 4]]
        [[1 5][2 4][1 3][4 5][1 2][3 4][2 3][4 5][3 4]]
        [[1 5][2 4][1 3][4 5][2 4][3 5][1 2][3 4][2 3]]
        [[1 5][2 4][1 4][2 3][1 2][3 5][2 3][4 5][3 4]]
        [[1 5][2 4][1 4][3 5][2 3][4 5][1 2][3 4][2 3]]
        [[1 5][2 4][2 3][4 5][1 2][3 4][2 3][4 5][3 4]]
        [[1 5][2 4][2 3][4 5][1 4][3 5][1 2][3 4][2 3]]
        [[1 5][2 4][2 5][3 4][1 3][4 5][1 2][3 4][2 3]]
        [[1 5][3 4][1 2][3 5][1 3][2 4][2 3][4 5][3 4]]
        [[1 5][3 4][1 2][4 5][1 3][2 4][2 3][4 5][3 4]]
        [[1 5][3 4][1 2][4 5][2 5][3 4][1 3][2 4][2 3]]
        [[1 5][3 4][1 3][2 4][1 2][3 5][2 3][4 5][3 4]]
        [[1 5][3 4][1 3][2 4][2 3][4 5][1 2][3 4][2 3]]
        [[1 5][3 4][1 3][2 5][1 2][3 4][2 3][4 5][3 4]]
        [[1 5][3 4][1 3][2 5][2 3][4 5][1 2][3 4][2 3]]
        [[1 5][3 4][1 4][2 3][1 2][3 5][2 3][4 5][3 4]]
        [[1 5][3 4][1 4][2 5][2 3][4 5][1 2][3 4][2 3]]
        [[1 5][3 4][2 3][4 5][1 2][3 4][2 3][4 5][3 4]]
        [[1 5][3 4][2 3][4 5][1 4][3 5][1 2][3 4][2 3]]
        [[1 5][3 4][2 4][3 5][1 2][4 5][1 3][2 4][2 3]]
        [[2 3][4 5][1 2][3 4][1 3][2 5][2 3][4 5][3 4]]
        [[2 3][4 5][1 2][3 5][1 4][2 3][2 4][3 5][3 4]]
        [[2 3][4 5][1 2][3 5][2 5][3 4][1 3][2 4][2 3]]
        [[2 3][4 5][1 3][2 4][1 2][4 5][2 4][3 5][3 4]]
        [[2 3][4 5][1 3][2 4][1 4][3 5][1 2][3 4][2 3]]
        [[2 3][4 5][1 3][2 5][1 4][3 5][1 2][3 4][2 3]]
        [[2 3][4 5][1 4][2 5][1 2][3 4][2 3][4 5][3 4]]
        [[2 3][4 5][1 4][3 5][1 2][3 4][2 3][4 5][3 4]]
        [[2 3][4 5][1 4][3 5][2 3][4 5][1 2][3 4][2 3]]
        [[2 3][4 5][1 5][2 4][1 2][3 4][2 3][4 5][3 4]]
        [[2 3][4 5][1 5][2 4][1 4][3 5][1 2][3 4][2 3]]
        [[2 3][4 5][1 5][3 4][1 2][4 5][1 3][2 4][2 3]]
        [[2 4][3 5][1 2][3 4][1 3][2 5][2 3][4 5][3 4]]
        [[2 4][3 5][1 2][4 5][1 3][2 4][2 3][4 5][3 4]]
        [[2 4][3 5][1 2][4 5][2 5][3 4][1 3][2 4][2 3]]
        [[2 4][3 5][1 3][2 5][1 2][3 4][2 3][4 5][3 4]]
        [[2 4][3 5][1 3][4 5][1 2][3 4][2 3][4 5][3 4]]
        [[2 4][3 5][1 3][4 5][2 4][3 5][1 2][3 4][2 3]]
        [[2 4][3 5][1 4][2 3][1 2][3 5][2 3][4 5][3 4]]
        [[2 4][3 5][1 4][2 3][1 3][4 5][1 2][3 4][2 3]]
        [[2 4][3 5][1 4][2 5][1 3][4 5][1 2][3 4][2 3]]
        [[2 4][3 5][1 5][2 3][1 2][3 4][2 3][4 5][3 4]]
        [[2 4][3 5][1 5][2 3][1 3][4 5][1 2][3 4][2 3]]
        [[2 4][3 5][1 5][3 4][1 2][4 5][1 3][2 4][2 3]]
        [[2 5][3 4][1 2][3 5][1 3][2 4][2 3][4 5][3 4]]
        [[2 5][3 4][1 2][4 5][1 3][2 4][2 3][4 5][3 4]]
        [[2 5][3 4][1 2][4 5][2 5][3 4][1 3][2 4][2 3]]
        [[2 5][3 4][1 3][2 4][1 2][3 5][2 3][4 5][3 4]]
        [[2 5][3 4][1 3][4 5][1 2][3 4][2 3][4 5][3 4]]
        [[2 5][3 4][1 3][4 5][2 4][3 5][1 2][3 4][2 3]]
        [[2 5][3 4][1 4][2 3][1 2][3 5][2 3][4 5][3 4]]
        [[2 5][3 4][1 4][2 3][1 3][4 5][1 2][3 4][2 3]]
        [[2 5][3 4][1 4][3 5][1 2][4 5][1 3][2 4][2 3]]
        [[2 5][3 4][1 5][2 3][1 2][3 4][2 3][4 5][3 4]]
        [[2 5][3 4][1 5][2 3][1 3][4 5][1 2][3 4][2 3]]
        [[2 5][3 4][1 5][2 4][1 3][4 5][1 2][3 4][2 3]]
    
    
    ----------
    
    
     - 6-input: 90 networks
    
        [[1 2][3 4][5 6][1 3][2 5][4 6][1 2][3 4][5 6][2 3][4 5][3 4]]
        [[1 2][3 4][5 6][1 3][2 6][4 5][1 4][2 3][5 6][2 4][3 5][3 4]]
        [[1 2][3 4][5 6][1 4][2 6][3 5][1 3][2 5][4 6][2 3][4 5][3 4]]
        [[1 2][3 4][5 6][1 5][2 3][4 6][1 2][3 6][4 5][2 4][3 5][3 4]]
        [[1 2][3 4][5 6][1 5][2 4][3 6][1 3][2 5][4 6][2 3][4 5][3 4]]
        [[1 2][3 4][5 6][1 6][2 4][3 5][1 3][2 5][4 6][2 3][4 5][3 4]]
        [[1 2][3 5][4 6][1 3][2 4][5 6][1 2][3 5][4 6][2 3][4 5][3 4]]
        [[1 2][3 5][4 6][1 3][2 6][4 5][1 4][2 3][5 6][2 4][3 5][3 4]]
        [[1 2][3 5][4 6][1 4][2 3][5 6][1 2][3 6][4 5][2 4][3 5][3 4]]
        [[1 2][3 5][4 6][1 4][2 5][3 6][1 3][2 4][5 6][2 3][4 5][3 4]]
        [[1 2][3 5][4 6][1 5][2 6][3 4][1 3][2 4][5 6][2 3][4 5][3 4]]
        [[1 2][3 5][4 6][1 6][2 5][3 4][1 3][2 4][5 6][2 3][4 5][3 4]]
        [[1 2][3 6][4 5][1 3][2 4][5 6][1 2][3 5][4 6][2 3][4 5][3 4]]
        [[1 2][3 6][4 5][1 3][2 5][4 6][1 4][2 3][5 6][2 4][3 5][3 4]]
        [[1 2][3 6][4 5][1 4][2 3][5 6][1 2][3 6][4 5][2 4][3 5][3 4]]
        [[1 2][3 6][4 5][1 4][2 6][3 5][1 3][2 4][5 6][2 3][4 5][3 4]]
        [[1 2][3 6][4 5][1 5][2 6][3 4][1 3][2 4][5 6][2 3][4 5][3 4]]
        [[1 2][3 6][4 5][1 6][2 5][3 4][1 3][2 4][5 6][2 3][4 5][3 4]]
        [[1 3][2 4][5 6][1 2][3 5][4 6][1 3][2 4][5 6][2 3][4 5][3 4]]
        [[1 3][2 4][5 6][1 2][3 6][4 5][1 4][2 3][5 6][2 4][3 5][3 4]]
        [[1 3][2 4][5 6][1 4][2 5][3 6][1 2][3 5][4 6][2 3][4 5][3 4]]
        [[1 3][2 4][5 6][1 5][2 3][4 6][1 2][3 6][4 5][2 4][3 5][3 4]]
        [[1 3][2 4][5 6][1 5][2 6][3 4][1 2][3 5][4 6][2 3][4 5][3 4]]
        [[1 3][2 4][5 6][1 6][2 5][3 4][1 2][3 5][4 6][2 3][4 5][3 4]]
        [[1 3][2 5][4 6][1 2][3 4][5 6][1 3][2 5][4 6][2 3][4 5][3 4]]
        [[1 3][2 5][4 6][1 2][3 6][4 5][1 4][2 3][5 6][2 4][3 5][3 4]]
        [[1 3][2 5][4 6][1 4][2 3][5 6][1 2][3 6][4 5][2 4][3 5][3 4]]
        [[1 3][2 5][4 6][1 4][2 6][3 5][1 2][3 4][5 6][2 3][4 5][3 4]]
        [[1 3][2 5][4 6][1 5][2 4][3 6][1 2][3 4][5 6][2 3][4 5][3 4]]
        [[1 3][2 5][4 6][1 6][2 4][3 5][1 2][3 4][5 6][2 3][4 5][3 4]]
        [[1 3][2 6][4 5][1 2][3 4][5 6][1 3][2 5][4 6][2 3][4 5][3 4]]
        [[1 3][2 6][4 5][1 2][3 5][4 6][1 4][2 3][5 6][2 4][3 5][3 4]]
        [[1 3][2 6][4 5][1 4][2 3][5 6][1 2][3 6][4 5][2 4][3 5][3 4]]
        [[1 3][2 6][4 5][1 4][2 5][3 6][1 2][3 4][5 6][2 3][4 5][3 4]]
        [[1 3][2 6][4 5][1 5][2 4][3 6][1 2][3 4][5 6][2 3][4 5][3 4]]
        [[1 3][2 6][4 5][1 6][2 4][3 5][1 2][3 4][5 6][2 3][4 5][3 4]]
        [[1 4][2 3][5 6][1 2][3 5][4 6][1 3][2 4][5 6][2 3][4 5][3 4]]
        [[1 4][2 3][5 6][1 2][3 6][4 5][1 4][2 3][5 6][2 4][3 5][3 4]]
        [[1 4][2 3][5 6][1 3][2 5][4 6][1 2][3 6][4 5][2 4][3 5][3 4]]
        [[1 4][2 3][5 6][1 5][2 4][3 6][1 2][3 5][4 6][2 3][4 5][3 4]]
        [[1 4][2 3][5 6][1 5][2 6][3 4][1 2][3 5][4 6][2 3][4 5][3 4]]
        [[1 4][2 3][5 6][1 6][2 5][3 4][1 2][3 5][4 6][2 3][4 5][3 4]]
        [[1 4][2 5][3 6][1 2][3 4][5 6][1 3][2 5][4 6][2 3][4 5][3 4]]
        [[1 4][2 5][3 6][1 2][3 5][4 6][1 3][2 4][5 6][2 3][4 5][3 4]]
        [[1 4][2 5][3 6][1 3][2 4][5 6][1 2][3 5][4 6][2 3][4 5][3 4]]
        [[1 4][2 5][3 6][1 3][2 6][4 5][1 2][3 4][5 6][2 3][4 5][3 4]]
        [[1 4][2 5][3 6][1 5][2 3][4 6][1 2][3 4][5 6][2 3][4 5][3 4]]
        [[1 4][2 5][3 6][1 6][2 3][4 5][1 2][3 4][5 6][2 3][4 5][3 4]]
        [[1 4][2 6][3 5][1 2][3 4][5 6][1 3][2 5][4 6][2 3][4 5][3 4]]
        [[1 4][2 6][3 5][1 2][3 6][4 5][1 3][2 4][5 6][2 3][4 5][3 4]]
        [[1 4][2 6][3 5][1 3][2 4][5 6][1 2][3 5][4 6][2 3][4 5][3 4]]
        [[1 4][2 6][3 5][1 3][2 5][4 6][1 2][3 4][5 6][2 3][4 5][3 4]]
        [[1 4][2 6][3 5][1 5][2 3][4 6][1 2][3 4][5 6][2 3][4 5][3 4]]
        [[1 4][2 6][3 5][1 6][2 3][4 5][1 2][3 4][5 6][2 3][4 5][3 4]]
        [[1 5][2 3][4 6][1 2][3 4][5 6][1 3][2 5][4 6][2 3][4 5][3 4]]
        [[1 5][2 3][4 6][1 2][3 6][4 5][1 4][2 3][5 6][2 4][3 5][3 4]]
        [[1 5][2 3][4 6][1 3][2 4][5 6][1 2][3 6][4 5][2 4][3 5][3 4]]
        [[1 5][2 3][4 6][1 4][2 5][3 6][1 2][3 4][5 6][2 3][4 5][3 4]]
        [[1 5][2 3][4 6][1 4][2 6][3 5][1 2][3 4][5 6][2 3][4 5][3 4]]
        [[1 5][2 3][4 6][1 6][2 4][3 5][1 2][3 4][5 6][2 3][4 5][3 4]]
        [[1 5][2 4][3 6][1 2][3 4][5 6][1 3][2 5][4 6][2 3][4 5][3 4]]
        [[1 5][2 4][3 6][1 2][3 5][4 6][1 3][2 4][5 6][2 3][4 5][3 4]]
        [[1 5][2 4][3 6][1 3][2 5][4 6][1 2][3 4][5 6][2 3][4 5][3 4]]
        [[1 5][2 4][3 6][1 3][2 6][4 5][1 2][3 4][5 6][2 3][4 5][3 4]]
        [[1 5][2 4][3 6][1 4][2 3][5 6][1 2][3 5][4 6][2 3][4 5][3 4]]
        [[1 5][2 4][3 6][1 6][2 3][4 5][1 2][3 4][5 6][2 3][4 5][3 4]]
        [[1 5][2 6][3 4][1 2][3 5][4 6][1 3][2 4][5 6][2 3][4 5][3 4]]
        [[1 5][2 6][3 4][1 2][3 6][4 5][1 3][2 4][5 6][2 3][4 5][3 4]]
        [[1 5][2 6][3 4][1 3][2 4][5 6][1 2][3 5][4 6][2 3][4 5][3 4]]
        [[1 5][2 6][3 4][1 3][2 5][4 6][1 2][3 4][5 6][2 3][4 5][3 4]]
        [[1 5][2 6][3 4][1 4][2 3][5 6][1 2][3 5][4 6][2 3][4 5][3 4]]
        [[1 5][2 6][3 4][1 6][2 3][4 5][1 2][3 4][5 6][2 3][4 5][3 4]]
        [[1 6][2 3][4 5][1 2][3 4][5 6][1 3][2 5][4 6][2 3][4 5][3 4]]
        [[1 6][2 3][4 5][1 2][3 5][4 6][1 4][2 3][5 6][2 4][3 5][3 4]]
        [[1 6][2 3][4 5][1 3][2 4][5 6][1 2][3 6][4 5][2 4][3 5][3 4]]
        [[1 6][2 3][4 5][1 4][2 5][3 6][1 2][3 4][5 6][2 3][4 5][3 4]]
        [[1 6][2 3][4 5][1 4][2 6][3 5][1 2][3 4][5 6][2 3][4 5][3 4]]
        [[1 6][2 3][4 5][1 5][2 4][3 6][1 2][3 4][5 6][2 3][4 5][3 4]]
        [[1 6][2 4][3 5][1 2][3 4][5 6][1 3][2 5][4 6][2 3][4 5][3 4]]
        [[1 6][2 4][3 5][1 2][3 6][4 5][1 3][2 4][5 6][2 3][4 5][3 4]]
        [[1 6][2 4][3 5][1 3][2 5][4 6][1 2][3 4][5 6][2 3][4 5][3 4]]
        [[1 6][2 4][3 5][1 3][2 6][4 5][1 2][3 4][5 6][2 3][4 5][3 4]]
        [[1 6][2 4][3 5][1 4][2 3][5 6][1 2][3 5][4 6][2 3][4 5][3 4]]
        [[1 6][2 4][3 5][1 5][2 3][4 6][1 2][3 4][5 6][2 3][4 5][3 4]]
        [[1 6][2 5][3 4][1 2][3 5][4 6][1 3][2 4][5 6][2 3][4 5][3 4]]
        [[1 6][2 5][3 4][1 2][3 6][4 5][1 3][2 4][5 6][2 3][4 5][3 4]]
        [[1 6][2 5][3 4][1 3][2 4][5 6][1 2][3 5][4 6][2 3][4 5][3 4]]
        [[1 6][2 5][3 4][1 3][2 6][4 5][1 2][3 4][5 6][2 3][4 5][3 4]]
        [[1 6][2 5][3 4][1 4][2 3][5 6][1 2][3 5][4 6][2 3][4 5][3 4]]
        [[1 6][2 5][3 4][1 5][2 3][4 6][1 2][3 4][5 6][2 3][4 5][3 4]] 
    

    Personally I’d check that the sorting network is correct before using it, rather than taking the word of some random page on the internet. Brute force “only” requires running it against finitely many inputs: “obviously” n! inputs is enough, and in fact so is 2**n (https://en.wikipedia.org/wiki/Sorting_network#Zero-one_principle).

    All of the optimal 5-networks involve “3” in the last swap, so picking the median in fewer swaps isn’t quite so easy as all that. It can be done in 6 comparisons, though. There’s way more code than you need here, if you can ignore the whining about the question:

    Code to calculate "median of five" in C#

    To pick a median you don’t necessarily do any swaps, other than perhaps one unconditional swap if you want to preserve all 5 values. A move might be adequate.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm looking for suggestions for debugging... If you view this site in Firefox or
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.