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

  • SEARCH
  • Home
  • 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 7915329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:25:05+00:00 2026-06-03T14:25:05+00:00

I have some data coming from the hardware. Data comes in blocks of 32

  • 0

I have some data coming from the hardware. Data comes in blocks of 32 bytes, and there are potentially millions of blocks. Data blocks are scattered in two halves the following way (a letter is one block):

A C E G I K M O B D F H J L N P

or if numbered

0 2 4 6 8 10 12 14 1 3 5 7 9 11 13 15

First all blocks with even indexes, then the odd blocks. Is there a specialized algorithm to reorder the data correctly (alphabetical order)?

The constraints are mainly on space. I don’t want to allocate another buffer to reorder: just one more block. But I’d also like to keep the number of moves low: a simple quicksort would be O(NlogN). Is there a faster solution in O(N) for this special reordering case?

  • 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-06-03T14:25:06+00:00Added an answer on June 3, 2026 at 2:25 pm

    Since this data is always in the same order, sorting in the classical sense is not needed at all. You do not need any comparisons, since you already know in advance which of two given data points.

    Instead you can produce the permutation on the data directly. If you transform this into cyclic form, this will tell you exactly which swaps to do, to transform the permuted data into ordered data.

    Here is an example for your data:

    0 2 4 6 8 10 12 14 1 3  5  7  9 11 13 15
    0 1 2 3 4 5  6  7  8 9 10 11 12 13 14 15
    

    Now calculate the inverse (I’ll skip this step, because I am lazy here, assume instead the permutation I have given above actually is the inverse already).

    Here is the cyclic form:

    (0)(1 8 4 2)(3 9 12 6)(5 10)(7 11 13 14)(15)
    

    So if you want to reorder a sequence structured like this, you would do

    # first cycle
    # nothing to do
    
    # second cycle
    swap 1 8
    swap 8 4
    swap 4 2
    
    # third cycle
    swap 3 9
    swap 9 12
    swap 12 6
    
    # so on for the other cycles
    

    If you would have done this for the inverse instead of the original permutation, you would get the correct sequence with a proven minimal number of swaps.

    EDIT:

    For more details on something like this, see the chapter on Permutations in TAOCP for example.

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

Sidebar

Related Questions

I have some JSON data coming from a service. I don't know the exact
I have some data coming from other tiers and it represents an EF object.
I have some data from database coming out in a loop. Each of these
I have a listView with some data coming from a server.I want to do
I have some decimal data coming from an external service. I need to format
So I have some data that's coming back from a database query, and the
I have some large vectors, the data of them are coming from some calculations
I have some data coming from server in form of string. The string might
I want to display some data relations (coming from an xml, for that matter)
I have a UITableView that was created from data coming from a mutable array.

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.