'What is the time complexity of concatenating two vectors in scala?

Given two vectors of length n and m respectively, what is the time complexity of concatenating them using the ++ operator? For lists, I believe it's O(n+m). Is it any better for vectors? Does any collection in scala have a better concatenation time than O(n+m)? Thanks for your help. :)



Solution 1:[1]

Adding a vector of length m to a vector of length n (len_n ++ len_m) takes O(m).

You can find the performance characteristics of each data structure on this page.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sanghyun Lee