1

I'm new to the concept of computational complexity and trying to understand the topic in depth. I went through some references mentioned by some old questions, however, I had this question and not sure if my understanding is correct.

I want to know the complexity of generating a uniform random vector, over $[0, 1]$, of size $N$ using say a random number generator in Python or Matlab.

Is it $\mathcal{O}(N)$ cause I'm generating $N$ random numbers and the complexity of generating each one of them is $\mathcal{O}(1)$ or is it simply $\mathcal{O}(1)$?

Chao
  • 13
  • 3
  • 4
    With what distribution? Over what space? What computational model do you want us to use? – D.W. Oct 21 '20 at 06:11
  • @D.W.: I tried to edit the post. I didn't understand fully your question regarding the computational model, can you explain what do you mean by that? Thanks. – Chao Oct 21 '20 at 06:45
  • Welcome to COMPUTER SCIENCE @SE. With sequential operation, you should be wary whenever space required seems to grow faster than time required. – greybeard Oct 21 '20 at 06:46

1 Answers1

1

You can't create a uniformly random number in $[0,1]$ in finite time, because that would require infinite precision.

Probably that's not what you want. Probably you want to generate a random float in the range $[0,1]$. Then we have to ask what assumptions you are willing to make about your pseudorandom number generator. For many of them it is probably reasonable to treat generating a random float in that range as taking $O(1)$ time. If so, you can create a $N$-dimensional vector with $N$ calls to that pseudorandom generator, i.e., in $O(N)$ time.

See How to come up with the runtime of algorithms?, How does one know which notation of time complexity analysis to use?, Is there a system behind the magic of algorithm analysis? and a good textbook for an overview of asymptotic running time analysis.

D.W.
  • 159,275
  • 20
  • 227
  • 470