Home > Algorithm | Excel VBA > CombSort11 Function & Procedure for VBA (コムソートで配列を並び替える)

CombSort11 Function & Procedure for VBA (コムソートで配列を並び替える)


今回のソート・アルゴリズムはCombSort と呼ばれるものです。これも、N * Log N の計算量です。エクセルVBAで、1,000,000 の数値の配列を20数秒で並び替えます。ヒープソート(Heapsort)も、アルゴリズムの理論値が同じですから、ほぼ同じような結果になります。N²のアルゴリズムのソート方法では、10,000の並び替えに同じくらいの時間がかかりました。その方法で、1,000,000 の数値配列の並び替えは無理かもしれません(実験しようとも思いません)。アルゴリズムを構築する者があまりハードウェアの分野に入り込まない方がいいかもしれません。

This sorting algorithm is called CombSort. The quantity of calculation is also N*LogN,and the array of the numerical value of 1,000,000 is sorted in about twenty seconds by Excel VBA. Heapsort also brings the almost same result, because of same theoretical value of an algorithm. By the sorting algorithm of N², sorting of 10,000 took about the same time. So that, by that method, sorting of the numerical array of 1,000,000 may be unreasonable. I think those who build an algorithm had better not seldom enter into the field of hardware.





コムソートは、ヒープソートに比べたら分かりやすく簡単なロジックをしています。両方共にとてもユニークなアルゴリズムなので、考案した人にはとても関心します。
Comb Sort は、配列の中の設定された間隔の位置の値を比較して並び替えます。最初の間隔は、配列の長さ÷1.3 (もし配列の長さが10,000 だとしたら、7692) の間隔の位置にある値を比較していきます。0 から 7692 先の位置を順番に比較していきますから、1回目は、2,308回の比較で済みます。 終了したら、次は5,916 (7692÷1.3) の間隔の位置にある値を比較して並べ替えます。最後の間隔は1となりますが、1.3くらいで割られていると数列の中に、9または10または11の数値が現われます。その間の9か10の間隔になる場合は、効率が悪いために11の間隔に再設定されます。(9→6→4→3→2→1)または、(10→7→5→3→2→1)の間隔で比較されるのを(11→8→6→4→3→2→1)に変えます。CombSort11は、そういった改善がされたソート方法です。

Sub と Function を使って Comb Sort を使用する方法です。Sub Program を呼ぶと配列が並び替えられます。CombSort11_Func を使うと "Temp" に並び替えられた配列が別に生成されます。用途に応じて使い変えます。

These are Sub & Function of Comb Sort. If Sub Program is called, then array will be sorted. If CombSort11_Func is used, the array will be sorted into "Temp" which will be generated independently. it can be changed according to a use.

Comments:0

Comment Form

Home > Algorithm | Excel VBA > CombSort11 Function & Procedure for VBA (コムソートで配列を並び替える)

Return to page top