Upload
pierre-wehbe
View
220
Download
0
Embed Size (px)
Citation preview
7/25/2019 Merge Sort Interview Question
1/3
tsasikumars Weblog
Just another WordPress.com
erge Sort Interview Question Part 2 October 27, 2
ted by ctsasikumar in Uncategorized.kback
Given the initial sequence : 3,41,52,26,38,57,9,49 ,at the last step in the merge sort .the seque
merged are3,26,52,41} and {38,49,57,9}3,26,41,52} and {9,38,49,57}3,9,41,52} and {26,38,49,57}3,9,26,38} and {41,49,52,57}s. b
Mergesort makes two recursive calls. Which statement is true after these recursive calls finiore the merge step?
he array elements form a heaplements in each half of the array are sorted among themselveslements in the first half of the array are less than or equal to elements in the second half of tayElements in the first half of the array are greater than or equal to elements in the second hal
ays. bGiven the initial sequence: {85 24 63 47 17 31 96 50}, at the last step in therge sort, the sequences to be merged are:
24 47 63 85} and {17 31 50 96}17 24 31 47} and {50 63 85 96}24 85} {47 63} {17 31} and {50 96}{17 24 31 47 63 85 96} and {50}depends on choice of pivots. aOn each iteration,the size of the sorted lists in a merge sortoublesalves
mains the same
https://ctsasikumar.wordpress.com/2007/10/27/merge-sort-interview-question-part-2/trackback/https://ctsasikumar.wordpress.com/2007/10/27/merge-sort-interview-question-part-2/trackback/https://ctsasikumar.wordpress.com/category/uncategorized/7/25/2019 Merge Sort Interview Question
2/3
ncreases 4 timess. aeach iteration, the size of the sorted lists doubles, form 1 to 2 to 4 to 8 to 16 to n.
What is the output of merge sort after the 1st pass given the following sequence of number7 9 11 142 13 1 5 7 9 11 145 12 13 7 9 11 145 7 9 11 12 13 14
5 7 9 12 13 11 14s:a
What is the output of merge sort after the 2nd pass given the following sequence of numbe 5 7 9 11 142 13 1 5 7 9 11 145 12 13 7 9 11 145 7 9 11 12 13 145 7 9 12 13 11 14
s:b
What is the output of merge sort after the 3rd pass given the following sequence of number7 9 11 142 13 1 5 7 9 11 145 12 13 7 9 11 145 7 9 11 12 13 145 7 9 12 13 11 14
s:c
In every pass, maximum number of comparisons in the merge sort is _________.1
g n*ns:a
What does the following pseudocode do?
ction sort(m)list left, rightngth(m) !1
urn m
ddle = length(m) / 2each x in m up to middle
d x to lefteach x in m after middle
d x to right
7/25/2019 Merge Sort Interview Question
3/3
= sort(left)ht = sort(right)ult = app(left, right)urn result
ifuick sortelection sortnsertion sortmerge sorts. d
omments
comments yet be the first.
The Regulus Theme.Blog at WordPress.com.
https://wordpress.com/?ref=footer_bloghttps://wordpress.com/themes/regulus/https://ctsasikumar.wordpress.com/2007/10/27/merge-sort-interview-question-part-2/#postComment