0

Suppose that there is a javascript array called fruitbox with length 10000.

Guess1

The actual structure of javascript array is literally linear.

(item delimiter item delimiter item delimiter ...)

It will generally take much more time, (about 1000 times more) to get fruitbox[5000] than fruitbox[5].

It is likely to find 5000th person/5th person in 10000 persons standing in line when your are standing at 1th person initially.

Guess2

The actual structure of javascript array uses indexing.

Given a natural number n, PC can get n-th element immediately.

It will generally take similar time to get fruitbox[5000] or fruitbox[5].

It is likely to find a word in 5000th page/5th page in 10000 page dictionary.


Which is true Guess1 or Guess2 ?

imida k
  • 239
  • 2
  • 9
  • I have honestly thought about this question, just haven't posted it. – Shmack Oct 02 '20 at 04:57
  • 1
    It’s the second one. – Ry- Oct 02 '20 at 05:03
  • 2
    What do you mean by "literally linear"? Is this a question about traversal time or how the array looks in memory? if it's the later, [How are JavaScript arrays represented in physical memory?](https://stackoverflow.com/questions/20321047/how-are-javascript-arrays-represented-in-physical-memory) points to Guess 2. – W-B Oct 02 '20 at 05:08
  • Thank you! It was about traversal time.There is no worry for creating large array. – imida k Oct 02 '20 at 05:26

0 Answers0