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 881683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:18:08+00:00 2026-05-15T12:18:08+00:00

This is not a homework. Just an interesting task :) Given a complete binary

  • 0

This is not a homework. Just an interesting task 🙂

Given a complete binary search three represensted by array. Sort the array in O(n) using constant memory.

Example:

Tree:

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

Array: 8, 4, 12, 2, 6, 10, 14, 1, 3, 5, 7, 9, 11, 13, 15

Output: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15

  • 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-15T12:18:08+00:00Added an answer on May 15, 2026 at 12:18 pm

    It is possible, people calling it homework probably haven’t tried solving it yet.

    We use the following as a sub-routine:

    Given an array a1 a2 ... an b1 b2 .. bn, convert in O(n) time and O(1) space to
    
    b1 a1 b2 a2 ... bn an
    

    A solution for that can be found here: http://arxiv.org/abs/0805.1598

    We use that as follows.

    Do the above interleaving for the first 2^(k+1) – 2 elements, starting at k=1 repeating for k=2, 3 etc, till you go past the end of array.

    For example in your array we get (interleaving sets identified by brackets)

     8, 4, 12, 2, 6, 10, 14, 1, 3, 5, 7, 9, 11, 13, 15   
    [ ][ ]
    
     4, 8, 12, 2, 6, 10, 14, 1, 3, 5, 7, 9, 11, 13, 15   (k = 1, interleave 2)
    [        ][        ]  
    
     2, 4, 6, 8, 10, 12, 14, 1, 3, 5, 7, 9, 11, 13, 15   (k = 2, interleave 6)
    [                      ][                     ]
    
     1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15   (k = 3, interleave 14)
    

    So the total time is n + n/2 + n/4 + … = O(n).
    Space used is O(1).

    That this works can be proved by induction.

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

Sidebar

Related Questions

For those with suspicious minds, this is not homework, just curious. Given a finite
this one is not homework, it just the fact that i've been out of
I'm trying to solve this problem, its not a homework question, its just code
Please note that this is not homework and i did search before starting this
This is not a homework question, just something at work that's bugging me. I'm
This is not homework, just a question about my code (I'm learning C++). I
Just to clarify this is NOT a homework question as I've seen similar accusations
This is not homework, just a learning exercise on my part. I have been
This is not homework . I am interested in setting up a simulation of
This is not homework, I need this for my program :) I ask this

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.