Edge Rewrite
// HTMLRewriter · presentation

This page was redesigned at the edge.

Cloudflare fetched the original article and streamed it through HTMLRewriter to apply an entirely new visual system without rebuilding the source page.

// request.cf · coarse context

A page that knows where it met you.

Only coarse request metadata is shown. This demo does not display or persist visitor IP addresses.

Country
US
Cloudflare location
CMH
Connection
HTTP/2
Language
Not provided

Ray ID: a21c16041aa0a151

Jump to content

Talk:Smoothsort

Page contents not supported in other languages.
Add topic
From Wikipedia, the free encyclopedia

Wikiproject

[edit]

I don't think this article belongs in the java wiki project - it's not about java, it just happens to have a java example. I'll drop it into comp sci instead. Paul Murray (talk) 01:12, 23 November 2009 (UTC)Reply

7049156 - longest reversed/random list that is properly calculated by java implementation, and i have no idea why... —Preceding unsigned comment added by 83.27.127.57 (talk) 14:56, 5 September 2010 (UTC)Reply

The problem is overflow in p. A n-bit p will work for arrays up to size proportional to L(n), where L(n) is the nth Leonardo number. Change both the declaration of the p variable in the sort() function, and the p parameter to the trinkle() function to use a 64-bit type (in C++, I use long long p), and there shouldn't be a problem until the array size reaches L(64) (which should be plenty big enough). James Barbetti (talk) 08:14, 24 November 2010 (UTC)Reply

Gif visualization problem

[edit]

Is it just me, or the frame 10 of the visualization (gif in the top right) depicts an incorrect behavior, because according to the description:

Smoothsort#Grow_the_string_by_adding_an_element_to_the_right

  1) The rightmost heap (the one that has just been created) becomes the "current" heap

so the heap of length 3 is now current

  2) While there is a heap to the left of the current heap and its root is larger than the current root and both of its child heap roots 

there is such heap, the heap of length 5, to the left of current one.

But, the visualization shows that the 3rd step of the algorithm is executed... The step two is omitted until very late into building the heaps. I wonder how step 2. and 3. are related actually, and how does it impact the time complexity of the algorithm.

Is there anyone around, who can say anything about it?

Thanks :) — Preceding unsigned comment added by Unk3mpt (talkcontribs) 14:17, 25 October 2012 (UTC)Reply

Pseudocode

[edit]

Here's some pseudocode for smoothsort using binary heaps, paraphrased from Hertel, that we may want to incorporate into the article later. Indices are 1-based.

algorithm smoothsort(A) is
    n := length(A)
    root := new array of ⌈log(n+1)⌉ integers

    // forward phase
    i := 0
    while i < n do
        k := ⌊log(n−i+1)⌋
        make-heap(i+1, i+2k−1)
        i := i+2k−1
        r := r+1
        root[r] := i
        restructure(A, root, r)

    // backward phase
    while i > 1 do
        size := root[r] − root[r−1]
        if size = 1 then
            r := r−1
        else
            // size > 1; split heap
            root[r+1] = root[r]−1
            root[r] := root[r+1] − (size−1)/2
            r := r+1
            restructure(A, root, r−1)
            restructure(A, root, r)
        i := i−1

// r is passed by value.
algorithm restructure(A, root, r) is
    while r > 1 and A[root[r−1]] > maxchildren(A, root[r]) do
        swap A[root[r−1]] and A[root[r]]
        r := r−1
    if r = 1 then
        heapify(root[r], 1)
    else
        heapify(root[r], root[r−1]+1)

maxchildren(A, i) returns the max of A[i] and its two children, if they exist. QVVERTYVS (hm?) 20:53, 29 November 2015 (UTC)Reply

Is smoothsort in fact a stable sort? I suspect it is not.

[edit]

This is a question for persons with more CS savvy than me. having:

1. read citation #4 (www.codeproject.com/articles/Fastest-In-Place-Stable-Sort), which states explicitly that smoothsort is NOT stable,

2. consulted the implementation (https://www.keithschwarz.com/interesting/code/?dir=smoothsort) described at https://www.keithschwarz.com/smoothsort/, and

3. tested the official Odin-language implemenation of smoothsort,

I don't believe that this is a stable algorithm. It seems that, being an evolved version of heapsort, it shares heapsort's instability. But I'm not a computer scientist, nor a mathematician, and I could be quite mistaken. What are your thoughts? ~2026-13326-37 (talk) 18:58, 1 March 2026 (UTC)Reply

I don't think it is stable. Bubba73 You talkin' to me? 19:01, 1 March 2026 (UTC)Reply
Smoothsort is not stable, but that is based on my WP:OR. Bubba73 You talkin' to me? 20:54, 1 March 2026 (UTC)Reply
And Sorting algorithm says that it is not stable. Bubba73 You talkin' to me? 20:58, 1 March 2026 (UTC)Reply
I've double-checked and agree with the above. Smoothsort's not stable. Proposal: that the article be edited. ~2026-13326-37 (talk) 17:58, 23 March 2026 (UTC)Reply