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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:48:47+00:00 2026-06-01T21:48:47+00:00

This was a homework problem but I missed the lecture where the lecturer explained

  • 0

This was a homework problem but I missed the lecture where the lecturer explained the solution and I still can’t figure it out…

If you are given n real numbers in the interval [0,1] (ie x1, x2, x3, …, xn) show that there is an algorithm that runs in worst case linear time that gives a permutation of these n numbers such that the sum of the differences of adjacent numbers is less than 2. The hint given was “buckets”.

  • 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-01T21:48:49+00:00Added an answer on June 1, 2026 at 9:48 pm

    Well, you can go this way. Split [0, 1] into k segments: [0, 1/k), [1/k, 2/k), …, [(k-1)/k, 1].

    You now go through your list and put into a new list first all the numbers that fit into 1st segment, than those that fit into the second etc. This can be done in one pass, so O(n).

    Consider what is the needed sum now. The diff of the numbers within the same segment is at most 1/k, the number of such differences n-(k-1). The rest (n-1) diffs are between the numbers from adjacent buckets, altogether (is that clear, why?) not more than 1. The sum is bound by (n-k+1)/k + (k-1)/k. You can make if sufficiently small for k large enough.


    More details:

    Let’s paint our differences into 2 colours: differences between the numbers from the same segment are painted blue, and differences between the numbers from different segments are painted red. Thanks to the ordering, we have first only the numbers in the 1st segment (possibly 0), than the numbers in the 2nd segment, and so on. So, we have first some blue differences, than a red difference, than again several blue differences, than again a red difference etc.

    Let’s see what is the number of red differences. There is obviously not more than k-1 red differences, right? Because each red difference jumps from one segment to a higher segment. The rest of the differences is blue.

    Now, each blue difference is not more than 1/k, because the minuend and subtrahend are from the same segment. And all the red differences altogether (that is, their sum!) do not exceed 1. (Skipping the rest for now, as this is a homework question.)


    Correction:
    The sum of all red differences doesn’t exceed 2-2/k. Why is that? Well, let’s see. The first red difference may be in the worst case from the beginning of some segment A to the end of some other segment B. The second is in the worst case from the beginning of B to the end of some other segment C. So, in the sum of the differences every segment except the first and the last is counted at most twice.

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

Sidebar

Related Questions

This is a question for a homework problem that I cant figure out: Question
XXX----Yep, its a Homework problem, but yea I'm stuck. Why doesn't this print out
This is my homework, but please read my problem description first. I have to
well I'm doing this homework but I'm still not viewing the fault... When I
This is a beginner C++ homework problem, I know about vector, but it is
Continuing on this problem , but I'll reiterate: For a homework assignment I have
I was taught HMM and given this homework problem. I understood a part of
The answer to this sample homework problem is "1,000,000", but I do not understand
Disclaimer: this was a homework problem. The deadline has passed now, so discussions can
Yesterday I submitted this problem, got terrific responses but my code still didn't work.

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.