(expanding on my comment)
Technically No
You need to be very careful here, as there is a difference between algorithmic time complexity and runtime. In the case you have described, the runtime may be O(n) but the algorithm itself is O(n+m).
This is because, without your external constraints, the algorithm's time complexity cannot be determined without knowing both m
and n
.
If you wanted to make the algorithm itself O(n), you would need to explicitly encode your external constraint that m<n
within the algorithm itself. Adding a check that aborts if m>n
would work.
Unless...
The above does not hold if m < n
by definition (ie it arises from a fundamental property of your data structures).
Say, for example, A
is an array and B
is an array composed of only the elements at the even indices of A
. Then m
is indeed < n
by definition, and no check is required.
In cases like these the answer is yes, the algorithm is O(n). In fact, it would be 'incorrect' (assuming you are going for a tight upper bound) to say it is O(n+m) since the asymptotic performance depends entirely on n
.