{{AFC submission|d|v|u=Peter.mlich|ns=118|decliner=Eviolite|declinets=20220328132507|reason2=nn|ts=20220328113914}} {{AFC comment|1=Seems to be entirely [[WP:OR|original research]]. Also see [[Wikipedia:Wikipedia is not for things made up one day]]. [[User:Eviolite|''ev''iolite]] [[User talk:Eviolite|(talk)]] 13:25, 28 March 2022 (UTC)}} ---- {{Short description|Sorting algorithm}} {{Draft topics|stem}} {{AfC topic|other}} == Description == {{No footnotes|date=May 2022}} {{Infobox Algorithm | name = {{PAGENAMEBASE}} | class = [[Sorting algorithm]] | category = Selection sort | data = [[Array data structure|Array]] | average-time = O(n\log n), 8.716 for n=1.000 | best-time = O(n\log n) | time = O(n\log n) | space = O(2) + index(n) | stability = [[Sorting algorithm#Classification|Stable]] }} How it work? {{PAGENAMEBASE}} create pyramid of minimal values from pairs. Repeat for first level of minimums... After end, remove minimum and rebuild pyramid branch. Properties: Algoritm need extra memory. Ist fast. Stable. == Statistics (average) ==
n         = 1.000
value-min = 0
value-max = n/2     // 50% of array contain some repeating value
------------------
compares  ~ 8.716   (Tim-sort ~8.680)
cycles    ~ 11.506  (Tim-sort ~20.969)
moves     ~ 1.753   (Tim-sort ~15.534, Select-sort ~2.979)
stability = stable
== Schematic of work ==
pavel vs. tomas    zdenek vs. michal  --- zapasy prvniho kola
  |         |         |         |
  +----+----+         +----+----+
       |                   |
     tomas               zdenek       --- zapasy druheho kola
       |                   |
       +---------+---------+
                 |
               zdenek                 --- a vitezem se stava zdenek, zdenek tedy odchazi (v zapasech by mel druhe misto tomas, ale u sortu to tak nejde :) )

poradi: zdenek, ?, ?, ?

pavel vs. tomas       -       michal  --- ted je nutne odchoziho nahradit ve vsech jeho zapasech od prvniho kola
  |         |         |         |     --- a zjistit v nich viteze
  +----+----+         +----+----+
       |                   |
     tomas               michal
       |                   |
       +---------+---------+
                 |
               tomas

poradi: zdenek, tomas, ?, ?

pavel       -         -       michal
  |         |         |         |
  +----+----+         +----+----+
       |                   |
     pavel               michal
       |                   |
       +---------+---------+
                 |
               pavel

3 1 2 2 0 3 1 0    // input

3-1 2-2 0-3 1-0    // compare pair from input and create level 1 of minimal
  1-2   0-----0    // new level 1 pyramid of index (for code i use index, for scheme i use value)
  1-----0 . .      // new level 2
        0 . .      // new level 3, save "0", cmp = 7
          . .
  1 2     3---0    // rebuild pyramid branch (select second value from input)
  1-----------0
            . 0    // save "0", cmp + 2
            . x
  1 2     3-1 x    // rebuild pyramid branch
  1---------1
  1                // save "1", cmp + 2
  x
3---2     3 1      // rebuild pyramid branch
    2-------1
            1      // save "1", cmp + 2
            x
3   2     3 x      // rebuild pyramid branch (when not even or odd value from input, use "x" (or -1), when "x" copy second index to next level)
    2-----3
    2              // save "2", cmp + 1
    x
3-----2   3        // rebuild pyramid branch (when -1, copy index to next level)
      2---3
      2            // save "2", cmp + 2
      x
3     x   3        // rebuild pyramid (when -1, copy index to next level)
3---------3
3                  // save "3", cmp + 1

          3        // save last "3"
===============
0 0 1 1 2 2 3 3    // output, suma(cmp) = 7+2+2+1+2+2+1 = 17
== Code (javascript) ==
==References== {{reflist}} == Links == * [https://en.wikipedia.org/wiki/Tournament_sort] Selection sort === External links === * {{in lang|en}} [https://mlich.zam.slu.cz/js-sort/sorting4-pokus.htm Test of sorting algorithms], generate statics (javascript) {{sorting}} [[:Category:Sorting algorithms]] [[:Category:Comparison sorts]]