algorithm - What is the time complexity of declaring a 2d array -


what worst case running time of declaring 2d array? 2d array not strictly square. have seen answers state o(n) , have seen answers state o(n²).

in mind, when declaring object array such this:

object[][] gridarray = new object[i][j];  //the number of elements n = i*j 

the time complexity when declaring array should o(n) scale linearly depending on how many elements there be. missing something?

it depends on mean n.

some may define n i , see j depended that, example square n * n, definition o(n^2), o(i * i) or o(i * j) if j in o(i).

however defined n = * j. yes, o(n) definition of n notation hides o(i * j) may more appropriate.


however note depends on whether language initializes array entries @ creation. languages don't that!

i guess code java, language sets every entry initial value. in case null, indeed creates i * j elements , sets them null, yielding o(i * j).

also take @ syntax creating two-dimensional array, explains in detail how code works.


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -