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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:07:00+00:00 2026-06-08T17:07:00+00:00

From Programming Pearls : Column 12: A Sample Problem : The input consists of

  • 0

From Programming Pearls: Column 12: A Sample Problem:

The input consists of two integers m and n, with m < n. The output is
a sorted list of m random integers in the range 0..n-1 in which no
integer occurs more than once. For probability buffs, we desire a
sorted selection without replacement in which each selection occurs
with equal probability.

The author provides one solution:

initialize set S to empty
size = 0
while size < m do
    t = bigrand() % n
    if t is not in S
        insert t into S
        size++
print the elements of S in sorted order

In the above pseudocode, bigrand() is a function returns a large random integer (much larger than m and n).

Can anyone help me prove the correctness of the above algorithm?

According to my understanding, every output should have the probability of 1/C(n, m).
How to prove the above algorithm can guarantee the output with the probability of 1/C(n, m)?

  • 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-08T17:07:01+00:00Added an answer on June 8, 2026 at 5:07 pm

    Each solution this algorithm yields is valid.

    How many solutions are there?
    Up to last line there (sorting) are n*(n-1)*(n-2)*..*(n-m) different permutations or
    n!/(n-m)! and each result has same probability

    When you sort you reduce number of possible solutions by m!.

    So number of possible outputs is n!/((n-m)!*m!) and this is what you asked for.

    n!/((n-m)!m!) = C(n,m)

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

Sidebar

Related Questions

From Programming Pearls: Column 12: Searching: There are two code segments: IntSetList(int maxelements, int
Here is a problem from Programming Pearls 2nd edition (Chapter 8.7): Considering a real
i have question from programming pearls problem is following show how to use Lomuto's
here is code from programming pearls this code prints random numbers in decreasing form
Question from Programming Pearls, 2nd edition: Given a sequential file containing 4,300,000,000 32-bit integers,
From programming pearls, it is known that array[1...n] has heap property if for all
I have this code from programming pearls #include <iostream> //#include <string> using namespace std;
Here are functions on strings from programming pearls. int wordncmp(char *p, char* q) {
i have implement this code from programming pearls and i think it should be
I have to implement quicksort. From Programming Pearls here is the code: public class

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.