0

Each of n distinct values is equally likely to be put into pile 1 or in pile 2, independent of each other. These piles are then sorted from smallest to largest. The two sorted piles are then merged into a single sorted pile by comparing the smallest values of each pile, putting the smaller of these two into a new pile, and then repeating with the new smallest remaining values in each pile.

Whenever one of the piles is empty, the remaining ones from the nonempty pile are then put into the merged pile in their sorted order. So the question is how to find the expected number of comparisons that are needed to merge the two sorted piles into a single sorted pile of all n items.

Answer:-At most,Mergesort requires number of comparisons < $n\log n$. But I want to know how it is computed when n is odd, using the two inequalities

[1] $\log (x+1)\leq\log(x)+1$

[2]$\log(x+\frac12)+\log(x-\frac12)\leq 2log(x)$

  • What are your thoughts on the question? – Yuval Filmus Jan 30 '16 at 15:05
  • @Yuval Filmus I know bubble sort, quicksort, find, insertion sort algorithm, inversions. I am just thinking how can I apply them here? If you have any hint, give me. – Win_odd Dhamnekar Jan 30 '16 at 16:35
  • Given the set of values falling into each pile, try to find an expression for the number of comparisons. Then take expectation over that. (This is only one possible approach. Another approach would be to calculate the probability that the items at position $i$ and $j$ are compared, and sum over all $i,j$.) – Yuval Filmus Jan 30 '16 at 16:37
  • The algorithm is given, you are asked to analyse it. Unless you flesh our your question by adding your own thoughts and a specific question, this is a duplicate of our reference question. Hint: start with writing the algorithm in pseudocode. – Raphael Jan 30 '16 at 16:50
  • 1
    @Raphael You seem to be closing questions too eagerly. This question calls for analysis of a randomized algorithm. The methods described in the reference question will not be sufficient. – Yuval Filmus Jan 30 '16 at 17:32
  • @YuvalFilmus. Agreed. I'm voting to reopen, since while the reference question is useful, the answer to this particular question needs quite a bit more than the reference question provides. In addition, the answer is sufficiently elegant that it shouldn't be swept under the rug. – Rick Decker Jan 30 '16 at 17:36
  • 2
    Even though it's not a dupe, it's still a problem dump. – David Richerby Jan 30 '16 at 18:34
  • @YuvalFilmus Aside from the fact there there really is no question here, it's the OPs job to target the question. I for one don't even see that the algorithm is randomized. But well. (I get that you vote by "I find interesting" as opposed to policy, but I hope you understand that I do the latter.) – Raphael Jan 30 '16 at 21:52
  • @Raphael You must have missed the phrase "expected number". – Yuval Filmus Jan 30 '16 at 21:59
  • @YuvalFilmus That doesn't imply that the algorithm is randomized, only that we should consider a random distribution over all inputs. Average-case analysis is covered by the reference question, by the way, if rather briefly. – Raphael Jan 30 '16 at 23:04
  • @Yuval Filmus quicksort algorithm requires, on average, approximately 2n$ln \frac n2$ comparisons to sort $\frac n2$ values of each pile in aggregate. Again these sorted piles are to be merged into single sorted pile. Conditioning on the 1st smallest rank of first comparison value, I have to find out expected number of comparisons Am I right? – Win_odd Dhamnekar Jan 31 '16 at 15:53
  • @VMD I fail to see the connection to quicksort. You are given a different algorithm to analyze. – Yuval Filmus Jan 31 '16 at 15:54
  • @Yuval Filmus I didn't understand what you mean to say.Do you mean to say quicksort can not be used here? – Win_odd Dhamnekar Jan 31 '16 at 15:59
  • @VMD This is not a question about quicksort. You are asked about the number of comparisons that your particular merging algorithm makes. The two piles are sorted for free. – Yuval Filmus Jan 31 '16 at 16:06
  • VMD, please don't use the comments for interactive discussion. This is not a discussion forum. The comments exist to help you improve your question. I encourage you to edit the question, based on the feedback you've gotten here. You might try showing what work you've already done and what your specific confusion is, and also try reading the linked question diligently and try applying the techniques shown there and edit the question to describe whether they were adequate for this problem or not and why not. – D.W. Feb 01 '16 at 06:32

0 Answers0