I have one Sorted ArrayList A and one unsorted ArrayList B, now I want to merge items of B in A such that A remains sorted.
Now I can think of only two ways to do this.
First one is to sort Arraylist B and then have two index positions one for Arraylist A and other for Araylist B, then we will move index one by one to insert B list's item in A.
Let us assume size of Arraylist A be n and size of Arraylist B bem.
Order of complexity will be O(m Log(m))(for sorting ArrayList B) + O(n + m).
Second Approach is just have an index on ArrayListaylist B and then use
Binary searchto place item from Arraylist B to A.
Order of complexity will be O(Log(n) * m).
Now can anybody please tell me which approach should i opt, also if you can think of any other approach better than these two then please mention.