1.

Why is the complexity of fetching from an Array be O(1)?

Answer»

In an Array, objects are stored in continuous memory location. So, if you KNOW the address of the BASE OBJECT then you will be able to FIND the address of the ith object.

address(a[i]) = address(a[0]) + i*size(object)

This term is independent of n, so the time complexity of fetching from an Array is O(1).



Discussion

No Comment Found