For faster navigation, this Iframe is preloading the Wikiwand page for ストゥージソート.

ストゥージソート

ストゥージソート
ストゥージソートのアニメーション
クラス ソート
データ構造 配列
最悪計算時間 O(nlog 3 /log 1.5)
最悪空間計算量 O(n)

ストゥージソート: Stooge sort)は、再帰を用いたソートアルゴリズムのひとつである。

計算時間はO(nlog 3 / log 1.5 ) = O(n2.7095...)であり、これはマージソートなどの効率的なアルゴリズムよりも、それどころか非常に効率の悪い単純なソートの例としてよく挙げられるバブルソートよりも遅い。

アルゴリズムは以下の通りである。

  • もし末尾の値が先頭の値より小さければ、それらを入れ替える。
  • 現在処理している部分列の要素数が3以上であれば、
    • リストの先頭2/3[1]に対してストゥージソートを行う。
    • リストの末尾2/3[1]に対してストゥージソートを行う。
    • リストの先頭2/3[1]に対して再びストゥージソートを行う。
  • そうでなければ終了。

実装

[編集]
 algorithm stoogesort(array L, i = 0, j = length(L)-1)
     if L[j] < L[i] then
         L[i]  L[j]
     if (j - i + 1) >= 3 then
         t = (j - i + 1) / 3
         stoogesort(L, i  , j-t)
         stoogesort(L, i+t, j  )
         stoogesort(L, i  , j-t)
     return L

脚注

[編集]
  1. ^ a b c この2/3の操作は切り上げで行う。切り捨てにより行うと特定のデータで失敗する。例えば、数列{3,4,5,1,2}を切り捨てにより昇順にストゥージソートすると数列{1,2,4,3,5}が返され不正となる。

参考文献

[編集]

外部リンク

[編集]


{{bottomLinkPreText}} {{bottomLinkText}}
ストゥージソート
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?