Content deleted Content added
m Maintain {{WPBS}} and vital articles: 1 WikiProject template. Create {{WPBS}}. Keep majority rating "Start" in {{WPBS}}. Remove 1 same rating as {{WPBS}} in {{WikiProject Computer science}}. Tag: |
|||
(33 intermediate revisions by 13 users not shown) | |||
Line 1:
{{WikiProject
{{WikiProject Computer science|importance=Low}}
}}
== Nomenclature issue ==
Line 101 ⟶ 102:
This section includes the statement: ''A k-way in-memory merge sort can also be constructed from a k-way merge algorithm, but his provides no benefits over the ordinary binary merge sort.'' On a processor with 16 registers, such as a PC in 64 bit mode, a 4-way merge sort using 10 or so pointers that a compiler optimizes by using registers for all those pointers will result in a 4-way merge sort being somewhat faster than a binary merge sort, and about as fast as quick sort. PC based benchmarks showed the 4-way merge sort was about 15% faster than binary merge sort. [[User:Rcgldr|Rcgldr]] ([[User talk:Rcgldr|talk]]) 19:19, 29 November 2015 (UTC)
:I made the statement more precise by specifying that the number of comparisons is being counted. [[User:Qwertyus|Q<small>VVERTYVS</small>]] <small>([[User talk:Qwertyus|hm?]])</small> 19:55, 29 November 2015 (UTC)
::I would recommend just removing the statement. A 4 way merge averages 3 compares for every move, versus 2 way merge averaging 1 compare for every move, but the 4 way does 1/2 the moves. So the number of compares of 4 way is 1.5 times the number of compares for 2 way, while the number of moves for 4 way is 1/2 the number of moves for 2 way. This is probably too much detail for the main article, which is about merge algorithms as opposed to sort algorithms. [[User:Rcgldr|Rcgldr]] ([[User talk:Rcgldr|talk]]) 22:26, 3 December 2015 (UTC)
:::Removed it. We might want to add a section about this to [[merge sort]] later. [[User:Qwertyus|Q<small>VVERTYVS</small>]] <small>([[User talk:Qwertyus|hm?]])</small> 09:49, 4 December 2015 (UTC)
*To clarify - a k-way in memory merge sort (using min-heap, recursion, or something similar to reduce k-1 compares to log2(k) compares), has the same time complexity as a 2-way merge. For n = power of k, then complexity = n logk(n) log2(k) = n log2(n), same as 2 way regardless of k. However the statement is ''no benefit'' as opposed to ''same time complexity''. Even with simple k-1 compare logic (3 compares per move), a 4 way merge sort of integers ends up being slightly faster than a 2 way merge sort, at least in the case of a PC in 64 bit mode (16 registers). The situation would probably be reversed if sorting an array of pointers to objects, since the compare overhead would be greater than the move overhead. The other issue is that a statement about the sort complexity belongs in the sort articles, instead of a merge article. [[User:Rcgldr|Rcgldr]] ([[User talk:Rcgldr|talk]]) 13:36, 7 December 2015 (UTC)
::What the original source cares about (and what I sloppily summarized as "no benefit") is the exact expected number of comparisons, not the big-O complexity. [[User:Qwertyus|Q<small>VVERTYVS</small>]] <small>([[User talk:Qwertyus|hm?]])</small> 15:22, 7 December 2015 (UTC)
:::The number of moves is also a factor, but the total number of operations remains the same, k=2, n log2(n) compares + n log2(n) moves = 2 n log2(n) total operations. k=4, 1 1/2 n log2(n) compares + 1/2 n log2(n) moves = 2 n log2(n) total operations. On my system, Intel 2600K 3.4ghz, in 64 bit mode (16 registers), a 4 way merge sort of psuedo random 64 bit unsigned integers is about 12% to 15% depending on the number of integers (12% for 4 million, 15% for 64 million). The 4 way merge sort on integers is about as fast as quick sort. The relative performance is affected by the overhead of compares versus the overhead of moves. [[User:Rcgldr|Rcgldr]] ([[User talk:Rcgldr|talk]]) 18:28, 7 December 2015 (UTC)
* Computational complexity is not about efficient use of registers on a particular machine. Furthermore, comparisons are usually not simple integer operations even though books on algorithms use that for clarity. [[User:Glrx|Glrx]] ([[User talk:Glrx|talk]]) 04:24, 9 December 2015 (UTC)
::As mentioned above, the issue with the removed statement was how it was worded ''no benefit'' as opposed to ''same time complexity'', and it probably belongs in sort algorithms and/or merge sort, not merge algorithms. [[User:Rcgldr|Rcgldr]] ([[User talk:Rcgldr|talk]]) 02:31, 12 December 2015 (UTC)
== Fake algorithms ==
A source code for <code>merge_int_dac</code> routine (consequently, for <code>merge_int_dac_mp</code>, too), added in [https://en.wikipedia.org/w/index.php?title=Merge_algorithm&oldid=693744853 this revision] by [[Special:Contributions/Mia0303|Mia0303]] under the [[Merge algorithm#Parallel merge]] section is incorrect. It '''would not even compile''' due to at least two major errors, let alone running and producing reasonable results!
Even when fixed, it will also be dramatically ineffective. Additionally it lacks description of the parameters, so it's hard to tell how it should be invoked. One can try to guess the parameters meaning, but that would mean reinventing the algorithm rather than learning it, which strongly contradicts an encyclopedic style. --[[User:CiaPan|CiaPan]] ([[User talk:CiaPan|talk]]) 08:52, 9 February 2016 (UTC)
:I've replaced the whole section by a summary of CLRS's parallel merge. [[User:Qwertyus|Q<small>VVERTYVS</small>]] <small>([[User talk:Qwertyus|hm?]])</small> 10:59, 9 February 2016 (UTC)
== Merge K-way merge algorithm article into this one ==
The article [[K-way merge algorithm]] largely duplicates content in the K-way merging section in this article, so I think it should be merged (this is not just a pun, I promise). I also suspect that the topic is not notable enough to merit its own article. — '''[[User:Pzoxicuvybtnrm|<span style="color:#750404;">P</span>]][[User talk:Pzoxicuvybtnrm|<span style="color:#254117;">C</span>]][[Special:Contributions/Pzoxicuvybtnrm|<span style="color:#062159;">B</span>]]''' 21:59, 9 December 2017 (UTC)
:I agree, the two articles have far too much overlap to be separate. Possibly if this article were expanded in a different direction the topics could be separately notable, but with the current content they are not. —[[User:David Eppstein|David Eppstein]] ([[User talk:David Eppstein|talk]]) 22:13, 9 December 2017 (UTC)
*'''Oppose''' The article is written in appropriate [[WP:SUMMARYSTYLE]], the K-way merging section summarize this article while this article gives significantly more details [[User:Trialpears|Trialpears]] ([[User talk:Trialpears|talk]]) 11:25, 15 May 2019 (UTC)
::Closing, given the uncontested policy-based argument. [[User:Klbrain|Klbrain]] ([[User talk:Klbrain|talk]]) 13:23, 23 June 2019 (UTC)
== Language support - C++ - std::inplace_merge ==
The term in place may be mis-leading here. std::inplace_merge may use auxiliary storage to implement the merge. It can throw an exception if it can't allocate enough memory.<ref>https://en.cppreference.com/w/cpp/algorithm/inplace_merge</ref>. Microsoft / Visual Studio attempts to allocate memory, but can perform the merge even if memory allocation fails.<ref>https://docs.microsoft.com/en-us/previous-versions/awc3s8k6(v=vs.140)</ref>.
{{reflist_talk}}
== Possible typo ==
should not it be a s+1 there? (the lower line beneath):
in parallel do
merge(A[i...r], B[k...s], C[p...t])
merge(A[r+1...j], B[s...ℓ], C[t+1...q])
<!-- Template:Unsigned IP --><small class="autosigned">— Preceding [[Wikipedia:Signatures|unsigned]] comment added by [[Special:Contributions/37.47.172.117|37.47.172.117]] ([[User talk:37.47.172.117#top|talk]]) </small>
== Difference between the merge algorithm and merge sort? ==
What is the difference between the merge algorithm and [[merge sort]]? The article says that the merge algorithm plays a critical role in the merge sort algorithm, but according to how the article describes the merge algorithm, it seems to me that it ''is the same thing'' as merge sort. So, what is the difference between the two algorithms, if there is a difference? I think this should be clarified early on in the article. —[[User:Kri|Kri]] ([[User talk:Kri|talk]]) 17:52, 23 August 2023 (UTC)
: {{re|Kri}} The merge algorithm takes two sorted chains (lists, sequences, arrays, ...) of data and creates a new chain (sometimes by copying the items of source data, sometimes by interleaving them, depending on the data structure in use), containing all items of both source chains in the proper order. Merge sort takes unsorted chain of data, decomposes it into multiple chains and successively merges them to construct a finał sorted chain of all source data. --[[User:CiaPan|CiaPan]] ([[User talk:CiaPan|talk]]) 20:14, 23 August 2023 (UTC)
::Yes. The merge algorithm is a subroutine in merge sort, not the whole merge sort. It is also used as a subroutine in some other algorithms unrelated to sorting. —[[User:David Eppstein|David Eppstein]] ([[User talk:David Eppstein|talk]]) 01:14, 24 August 2023 (UTC)
:::{{re|David Eppstein}} Thank you for clarification. {{smiley}} [[User:CiaPan|CiaPan]] ([[User talk:CiaPan|talk]]) 10:33, 29 August 2023 (UTC)
::::Thank you for the answers; that makes sense! I have updated the text under the image in the article to reflect that. —[[User:Kri|Kri]] ([[User talk:Kri|talk]]) 19:42, 29 August 2023 (UTC)
: {{re|Kri}} What David said about a ''𝄪subroutine𝄪'' above applies to words ''𝄪successively merges them𝄪'' in my answer. --[[User:CiaPan|CiaPan]] ([[User talk:CiaPan|talk]]) 10:33, 29 August 2023 (UTC)
|