I’ve seen the operation of copying a string described as O(n), where n is the length of the string, because it’s assumed that we need to iterate through each character of the string and copy it individually. However, is it not possible for a compiler to generate instructions that can copy an entire block of memory in constant time? Does such a capability even exist on today’s common architectures?
Share
Not as far as I know.
However, for O() notation to be meaningful, you have to define the cost of each basic operation first. This is often omitted, because “it’s obvious”. And most of the time it really is. Your (hypothetical) scenario is a good example of a situation where defining the costs is essential.
Another, slightly more useful example is in the analysis of disk or tape storage search/sort algorithms.