Does it have to compare every element one by one?
In such case it must be O(n) right?
It doesn't necessarily compare all the elements.
If the two vectors are of different lengths, it can return false based only on the difference in length, in constant time.
Otherwise, yes, it has to compare elements until it encounters a difference (all the elements if the two are equal).
when you want to compare two vectors.
Generally, in our program, the size of two vectors should already be given (not a variable as the input size) , in that situation, the comparison between two vectors is O(1) since it must finish the comparison in a fixed time.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.