What's the dimension?

What's the minimum value of n n for which, the average distance between any 2 points selected randomly in a unit hypercube ( n- dimensional cube ) is greater than 2 2 ?


The answer is 25.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

2 solutions

Jason Carrier
Jul 5, 2019

I know this is a computer science question, but the solution can be worked out exactly with a bit of calculus. First, the distance formula. In 2 dimensions, it is d = ( x 2 x 1 ) 2 + ( y 2 y 1 ) 2 d = \sqrt{(x_2-x_1)^2 + (y_2-y_1)^2} . This generalizes to higher dimensions by adding more terms under the square root. In other words, the total distance squared is the sum of the squares of the distances in each dimension. Since the question asks about the average distance, we can do the same but using the sum of the average distance squared. The average of the distance squared is given by:

1 1 0 1 1 0 0 1 0 1 ( x y ) 2 d x d y = 1 6 \frac{1}{1-0}\frac{1}{1-0}\int_0^1 \int_0^1(x-y)^2 dx dy=\frac 16

Since this is true in each dimension, the average distance in n n dimensions is n / 6 \sqrt{n/6} . 24 dimensions makes this exactly 2, so we need 25 dimensions to make the average greater than 2.

Note: I have used x and y here because I’m too lazy to type x 1 x_1 and x 2 x_2 multiple times. x and y are independent values along the same dimension, not perpendicular ones

Actually, you cannot generalise the integral and the closed form solution of s q r t ( n / 6 ) sqrt(n/6) is wrong. There is no closed form solution for a general n. There are specific values of n for which you can get the answer in terms of known functions. However, your estimate is close and that's why the approximation worked. For more information, look up, hypercube line picking.

Kunal Gupta - 1 year, 11 months ago
Kunal Gupta
Sep 11, 2018

Here's a Python script that implements Monte Carlo simulation.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
from random import random
from math import sqrt
n = 1
while True:
  dis = 0.000000
  N = 1000000
  i = 0
  while i<N:
    temp = 0
    for j in range(n):
      temp+=(random()-random())**2
    dis+=sqrt(temp)
    i+=1
  dis/=N
  if dis>2:
    print n
    break
  n+=1

Which on running gives
Output 25

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...