What's The Next Step of Merge?

Use the merge algorithm to find the third step of the merge of A and B. Here are the first two steps:

Initial State A = [2,4,9] B = [1,7,13,15] Results = [ ]
First Step A = [2,4,9] B = [7,13,15] Results = [1]
Second Step A =[4,9] B = [7,13,15] Results = [1,2]
A = [9] B = [7,13,15] Results = [1,2] A = [9] B = [13,15] Results = [1,2,4,7] A = [ ] B = [ ] Results = [1,2,4,7,9,13,15] A = [9] B = [7,13,15] Results = [1,2,4]

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Geoff Pilling
Feb 2, 2017

For the third step, you compare the smallest of the first (smallest) elements of A and B, and move this element over to Results. In this case, the smaller value is 4 (in element A), which gets moved to the end of Results.

So, you wind up with A = [ 9 ] , B = [ 7 , 13 , 15 ] , Results = [ 1 , 2 , 4 ] \boxed{A = [9], B = [7,13,15] \text{, Results} = [1,2,4]}

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...