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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:12:09+00:00 2026-05-23T16:12:09+00:00

Given is an array of size n which was divided to n/k intervals of

  • 0

Given is an array of size n which was divided to n/k intervals of size k each. The values in each interval are bigger than the ones in the interval to its left and smaller than the ones in the interval to its right. I want to sort those values in the minimum time that I can.

The naive solution that I thought of is just to sort all the values in each interval which will “cost” O(k log k), for a total cost for all the n/k intervals of O(n log k). I wonder if there’s something more efficient.

Now I know that in each interval I have no more than log log k different values, I need to come up with a quicker algorithm. I’d love your help with this.

Thanks!

  • 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-23T16:12:09+00:00Added an answer on May 23, 2026 at 4:12 pm

    Here’s an extremely ugly answer:

    1. Take the first interval;
    2. Since logK should be small, we allocate logK binary tree nodes, and we place the first element in the middle;
    3. For the rest of the elements, we use method similar to binary search to search if it is already included, or we add this element;
    4. Produce a sorted list with all the values in the interval;
    5. Use Counting Sort with this list on the interval;
    6. Do this for all the intervals.
    

    The time used for 2,3 is O(K*logloglogK) since the search takes at most logloglogK (log on the loglogK elements) and repeated for K times. 4 use at most O(loglogK) time to walk through all the nodes with values. 5 takes O(K) time, similar to the Counting Sort. So the total time should be O(nlogloglogK).

    Any question is welcomed since I am really sleepy and cannot guarantee that I am thinking straightly.

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

Sidebar

Related Questions

You're given an array of size n, containing arbitrary boolean values. What is the
Given an array of items, each of which has a value and cost ,
I was reading a book when I found that array size must be given
Given two sorted arrays: A and B . The size of array A is
Given an array of characters which forms a sentence of words, give an efficient
Given an array of 2n elements of which n elements are same and the
We have an array A of integers of size N. Given another array B
I had previously posted a question, Given an array, find out the next smaller
Given an array of size N I need to find the min number of
This problem is taken from interviewstreet.com Given array of integers Y=y1,...,yn, we have n

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.