Say I am given an array, and a function called replace
:
void replace(from, to, items[])
whose job is to replace the array elements in the range [from, to)
with the elements in items
.
I'll assume the maximum size of the array is known beforehand, so I can ensure the array will never overflow.
My question is, if I am given a list of replacements (e.g. elements of the form (from, to, items)
), is it possible for me to obtain the final resulting array with a faster time complexity than performing each operation sequentially?
In other words, is there any advantage to knowing the sequence of operations beforehand, or is it no better than being given each operation one by one (in terms of the asymptotic time complexity)?
Note: It seems like the question is confusing; I did not intend to imply that the number of elements replacing a given range is the same as the size of that range! It could be fewer or more, causing shifting, and the point of the question was was to ask if knowing them beforehand could avoid extra work like shifting in the worst case.