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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:34:11+00:00 2026-05-25T14:34:11+00:00

Say I were given a set of weights adding up to 1, and I

  • 0

Say I were given a set of weights adding up to 1, and I lined them up one after another to make a series of bins with length proportional to their weight. I assign each bin an integer corresponding to its place in line.

Given any number in [0,1], I would like to be able to check which index corresponds to the bin this number lands in. Can I come up with an algorithm to do this in constant time?

A logarithmic time solution is straightforward, but I’m hoping for one better!

  • 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-25T14:34:12+00:00Added an answer on May 25, 2026 at 2:34 pm

    This can probably be accomplished using the alias method, which can be used to generate random samples from a discrete distribution in time O(1). I believe that you can adapt this algorithm to solve your problem by simply inverting the transform so that instead of mapping from a uniform random variable to a discrete bucket, you map from a discrete bucket to a uniform variable. From there, you can determine which bucket the value falls in.

    Hope this helps!

    EDIT: I recently wrote an extensive write-up of the alias method and other related tricks. Hopefully this makes the algorithm and its intuition clearer and easier!

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

Sidebar

Related Questions

I need to generate a set of coordinates in Erlang. Given one coordinate, say
Given a set of letters, say from A.. F, how can one generate a
For a given entity set, say, WHO_TYPES, I want to limit the columns to
I came across this question: say given two weights 1 and 3, u can
We were given a set of ASMX services to consume. We have no say
So say I am given a set of points: 0, 0 0, 5 5,
I have a given set of alphabets say 11 letters. I want to find
Is this possible? Given a div of say max-height 400 with overflow set to
When a set is given say {1,2,3,4,5,6} The task is to separe pair of
Given a set of strings, say: Alice Bob C Ca Car Carol Caroling Carousel

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.