Question: Multi Merge . . . . . . . . . . . . . . . . . . . . . . .

Multi Merge ....................................................................[15] Consider the following slight variant of the Merge procedure we saw in class. The inputs are two sorted arrays of integers, B,C. Important technical note: As discussed in class, we use the convention that accessing an out-of-bounds index returns \infty .
Algorithm 3 Procedure Merge(B,C)
1: Initialize A to be the empty vector
2: Define i =0, j =0, n =|B|+|C|
3: for t =0,...,n 1 do
4: if B[i]<= C[j] then
5: append B[i] to A
6: increment i
7: else
8: append C[j] to A
9: increment j
10: end if
11: end for
(a)[2] If B and C are two arrays of not-necessarily-equal length, argue (with 2-3 lines of reasoning) that the Merge function takes time O(|B|+|C|).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!