Machine-translated by Google. Questions are authored in English.
Top

Discussion

Mergesort makes two recursive calls. Which statement is true after these two recursive calls finish, but before the merge step ?

  • A.The array elements form a heap.
  • B.Elements in each half of the array are sorted amongst themselves.
  • C.Elements in the first half of the array are less than or equal to elements in second half of the array.
  • D.All of the above

Answer: B

After the two recursive calls and before the merge, the elements in each half of the array are sorted among themselves. Mergesort sorts the left half and the right half separately and then merges them, so at this point each half is in order, but there is no relation between the halves, so the first half need not be smaller than the second and the array does not form a heap. The statement that all of them hold is therefore false. The merge step then combines the two sorted halves into one, and it is only after that step that the whole array is in order.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.