2 ms·
My understanding from my algorithms class is that it is simply a matter of choosing your abstraction. Big O is meant to provide a general framework for qualifyi
by xKingfisher 11y ago
My understanding from my algorithms class is that it is simply a matter of choosing your abstraction. Big O is meant to provide a general framework for qualifying and comparing algorithms free of machine dependent factors like execution time. It is not possible to account for every possible facet of every operation so some operations are chosen to be O(1) even though in reality they take multiple machine code instructions or have slightly varying real world performance. Saying array access is O(1) also does not account for different architectures or cache misses, which have major performance implications.
So in the case of arrays, since we do not need to read A[0] and A[1] to access A[2], it makes more sense to say it is an O(1) operation.
Another example is arithmetic. Addition and multiplication are considered O(1) operations for many algorithms even though multiplication is slower than addition. At a lower level, addition could be considered O(log n), since the binary representation of numbers has O(log n) bits of input. But the abstraction of addition as an O(1) operation is more useful at a higher level.
Also in Big-O, we drop everything but the major term, so accessing element 0 may be O(1.0001) while accessing element 20 is O(1.0003), they are both still considered O(1).
This is purely my takeaway from my undergrad algorithms class, so it may not be entirely accurate. Please correct me if I am wrong or misleading.