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

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -