What would be the time complexity associated with concatenating arrays? Not merging them as in merge sort, but simply concatenating them using System.arraycopy()
. Thanks.
Asked
Active
Viewed 399 times
0

Ruben Martinez Jr.
- 3,199
- 5
- 42
- 76
-
What do you think it would be? Why do you think so? Why do you have doubts? – Sotirios Delimanolis Aug 25 '14 at 21:22
-
1Surely, it's just adding to the new array with all the entries of the other? Which would be O(n). – Rudi Kershaw Aug 25 '14 at 21:22
-
^That's what I think, but I'm trying to ask for expertise from someone who might know more about the inner workings of the function. – Ruben Martinez Jr. Aug 25 '14 at 21:23
-
read this question http://stackoverflow.com/questions/18638743/is-it-better-to-use-system-arraycopy-than-a-fast-for-loop-for-copying-array – Tareq Salah Aug 25 '14 at 21:24
-
@Andreas - Rather than putting this on hold as a duplicate, I think this subject would benefit from a more canonical answer, referencing arraycopy()'s source code. Which could be difficult because it's probably written in C buried away somewhere. – Rudi Kershaw Aug 25 '14 at 21:29
-
@Rudi: I think it'd be more appropriate to add a more canonical answer to the question where this was asked originally, and mark duplicate questions as duplicates. Besides, `System.arraycopy()` can perform a native `memcpy` operation, for which we don't have source code, but whose complexity should be obvious. – StriplingWarrior Aug 25 '14 at 21:33
-
1@StriplingWarrior - On second thoughts agreed. And besides that, after a little digging around the implementation of arraycopy() is platform dependent so there probably isn't a single canonical answer anyway. – Rudi Kershaw Aug 25 '14 at 21:34