Skip to main content
added 69 characters in body
Source Link

if you access to data by number (e.g. "i"), it is fast when you use array. because it goes to element directly

But, other data structure (e.g. tree, list), it needs more time, because it start from first element to target element. when you use list. It needs time O(n). so, it is to be slow.

if you use iterator, compiler knows that where you are. so It needs O(1) (because, it start from current position)

finally, if you use only array or data structure that support direct access(e.g. arraylist at java). "a[i]" is good. but, when you use other data structure, iterator is more efficient

if you access to data by number (e.g. "i"), it is fast when you use array. because it goes to element directly

But, other data structure (e.g. tree, list), it needs more time, because it start from first element to target element. when you use list. It needs time O(n). so, it is to be slow.

if you use iterator, compiler knows that where you are. so It needs O(1) (because, it start from current position)

finally, if you use only array. "a[i]" is good. but, when you use other data structure, iterator is more efficient

if you access to data by number (e.g. "i"), it is fast when you use array. because it goes to element directly

But, other data structure (e.g. tree, list), it needs more time, because it start from first element to target element. when you use list. It needs time O(n). so, it is to be slow.

if you use iterator, compiler knows that where you are. so It needs O(1) (because, it start from current position)

finally, if you use only array or data structure that support direct access(e.g. arraylist at java). "a[i]" is good. but, when you use other data structure, iterator is more efficient

Source Link

if you access to data by number (e.g. "i"), it is fast when you use array. because it goes to element directly

But, other data structure (e.g. tree, list), it needs more time, because it start from first element to target element. when you use list. It needs time O(n). so, it is to be slow.

if you use iterator, compiler knows that where you are. so It needs O(1) (because, it start from current position)

finally, if you use only array. "a[i]" is good. but, when you use other data structure, iterator is more efficient