Solving Complexity Issues: Merging Algorithms

Click For Summary

Discussion Overview

The discussion revolves around the complexities involved in merging sorting algorithms, particularly focusing on the efficiency of merging algorithms with similar complexities and the implications of different sorting strategies. Participants explore theoretical aspects, potential proofs, and the practical challenges of analyzing algorithm performance.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Homework-related
  • Mathematical reasoning

Main Points Raised

  • One participant questions the efficiency of merging two sorting algorithms with the same complexity, suggesting that it may be pointless in terms of running time.
  • Another participant proposes that merging could still be beneficial if it reduces the constant factor in the asymptotic run time.
  • There is a discussion on the complexity of heap sorting k/n elements into buckets and how merge sort might perform under those conditions.
  • Concerns are raised about the intricacies involved in determining optimal input sizes for partitioning, which some participants find adds complexity to the problem.
  • One participant reflects on the challenges of analyzing the merging process, describing it as "messy" and expressing uncertainty about achieving a final answer regarding the bucket ratio that would improve performance.
  • Several participants critique the use of informal terms like "icky" and "messy," suggesting a need for more precise language in the discussion.
  • There is mention of applying Master's theorem to the problem, indicating attempts to formalize the analysis despite the perceived complexity.

Areas of Agreement / Disagreement

Participants express differing views on the efficiency and practicality of merging algorithms with similar complexities, with no consensus reached on the best approach or the implications of their analyses.

Contextual Notes

Participants acknowledge limitations in their analyses, including the complexity of determining optimal partition sizes and the challenges of formalizing their reasoning. Some discussions remain unresolved, particularly regarding the effectiveness of different sorting strategies.

rover13
Messages
1
Reaction score
0
Homework Statement
Suppose you want to improve Merge Sort by first applying Heap Sort to a number of consecutive subarrays. Given an array A, your algorithm subdivides A into subarrays A1, A2 · · · Ak, where k is some power of 2, and applies Heap Sort on each subarray Ai alone. The algorithm proceeds into merging pairs of consecutive subarrays until the array is sorted. For example, if k = 4, you first apply Heap Sort to sort each Ai and then you merge A1 with A2 and A3 with A4, then you apply the merge function once to get the sorted array. (a) Does the proposed algorithm improve the asymptotic running time of Merge Sort when k = 2? How about the case k = log n (or a power of 2 that is closest to log n)? Justify. (b) Is the proposed algorithm stable? Is it in-place? Prove your answers.
Relevant Equations
?
So I have this problem to solve, I was thinking that for k=2, the threshold value is too low and inefficient, but I'm not sure when k is at logn or more. If 2 sorting algorithms have the same complexity, won’t merging them be pointless in terms of running time? For b), i think the merged algorithm would be stable and not in place.
 
Physics news on Phys.org
rover13 said:
Homework Statement:: (a) ... Justify. (b) ... Prove your answers.
Your answers are just guesses, not the justifications and proofs that are asked for. You need to write things down like "let merge sort have asymptotic run time ## M(n) = k n \log n ##" and work from there.

rover13 said:
If 2 sorting algorithms have the same complexity, won’t merging them be pointless in terms of running time?
Not if you can improve ## k n \log n ## to, say, ## \frac12 k n \log n ## which would be (asymptotically) twice as fast.
 
  • Like
Likes   Reactions: sysprog
Analyze the complexity of heap sorting k/n elements into buckets and then things get icky. How does merge sort perform with those conditions? Does it have better asymptotic behavior?
 
valenumr said:
Analyze the complexity of heap sorting k/n elements into buckets and then things get icky. How does merge sort perform with those conditions? Does it have better asymptotic behavior?
What exactly do you mean by "things get icky"? Some aspects of the problem, e.g. how best to determine the optimal input size on which to partition, introduce some intricacies, but isn't that part of why the problem is included in a CS course of study?
 
  • Like
Likes   Reactions: berkeman and pbuk
sysprog said:
What exactly do you mean by "things get icky"? Some aspects of the problem, e.g. how best to determine the optimal input size on which to partition, introduce some intricacies, but isn't that part of why the problem is included in a CS course of study?
Gosh, this was a while ago thinking on the problem. I'll try and recollect, but I think basically, it's pretty easy to analyze the first step (heap sorting n approximately equal sized arrays). It gets messy thinking how that is helpful for merge sort. I think you can sort each array by heap top node, pop and reheap each array, sort the arrays again, and then wash, rinse, and repeat. It's an interesting problem, but I really never managed to work though it on paper. It was messy. Since merge sort is not in place, it seems feasible, but I never got I final answer for the bucket ratio that would give improvement.
 
@valenumr, I'm pretty sure that I'm not out of line in supposing that in this context such terms as "icky" and "messy" are more than a little bit lacking in precision.
 
Last edited:
sysprog said:
@valenumr, I'm pretty sure that I'm not out of line in supposing that in this context such terms as "icky" and "messy" are more that a little bit lacking in precision.
Fair point. I tried applying Master's theorem to my approach to the problem, but I guess when I use such terms I mean there was much more writing than I had expected...
 
sysprog said:
@valenumr, I'm pretty sure that I'm not out of line in supposing that in this context such terms as "icky" and "messy" are more that a little bit lacking in precision.
And to be fair, call it the opposite of "elegant". I never got to such an approach.
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 12 ·
Replies
12
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 17 ·
Replies
17
Views
3K