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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:16:49+00:00 2026-05-29T09:16:49+00:00

This is Interviewstreet puzzle: We have a country containing N cities. Each day we

  • 0

This is Interviewstreet puzzle:

We have a country containing N cities. Each day we choose 2 cities such that there is no road between them and build a road between them. We choose each pair of nonadjacent cities with equal probability. Let X be the number of days before we obtain a connected country. What is the expected value of X? Output the integer part of answer.

What they are really asking is what number of edges m is needed (on average) for a random graph G(n, m) to become connected.

After writing a program that actually performed the experiment, I came up with this ‘solution’ that passes 9/10 tests

$f = fopen('php://stdin', 'r');
$n = intval(fgets($f));
echo round(1.25 * $n * log($n, 10));

So can it be solved with a single formula? What is the right way of finding likelihood of connectedness of random graph?

  • 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-29T09:16:49+00:00Added an answer on May 29, 2026 at 9:16 am

    You should check out the classic paper of Erdos and Renyi from 1960 entitled “On the evolution of random graphs”. It contains complete probabilistic bounds for number of components, size of the largest components, etc.

    Here’s a bit of the math set-up to get you started.

    Let G(n,m) be the simple random graph on n vertices with m edges. Let X_k be the number of edges added while there are k connected components until there are k-1 connected components. For example, initially there are n connected components, so adding the first edge results in n-1 connected components so X_n = 1. Similarly, the second edge also removes a component (though this happens in one of two ways) so X_n-1 = 1 as well. Define

    X = X_n + X_n-1 + ... + X_2
    

    The goal is to compute E(X), the expected value of X. By additivity, we have

    E(X) = E(X_n) + E(X_n-1) + ... + E(X_2) 
    

    It’s not too hard to show that the probability that an edge added while there are k components reduces the number of components has a lower bound of (k-1)/(n-1). Since X_k is the random variable with probability of success given by this amount, the lower bound gives an upper bound for the expectation of X_k:

    E(X_k) <= (n-1)/(k-1)
    

    Combining this, we get an asymptotic upper bound for E(X) by n log n.

    With a bit more work and some hints from the Erdos-Renyi paper, you can probably deduce an exact formula.

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

Sidebar

Related Questions

This problem is taken from interviewstreet.com Given array of integers Y=y1,...,yn, we have n
I am trying to solve this challenge on InterviewStreet: https://www.interviewstreet.com/challenges/dashboard/#problem/4edb8abd7cacd I already have a
I came across this question from interviewstreet.com Machines have once again attacked the kingdom
I have almost solved this quadrant queries problem of Interviewstreet using segment trees with
This question might have been asked many times but still there are many factors
This may be an unusual question, but are there any resources people have come
This was a question at a programming contest that finished yesterday at interviewstreet: Alice
This should be a simple one: I have an observableArray object called To in
This is a very newbie question I fear... I was wondering if there are
This may be a wild strange dream. I dreampt that I could put a

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.