第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

您能否給我我制作的這個新選擇排序算法的時間近似值(例如 n^2 , n*2 , nlogn )

您能否給我我制作的這個新選擇排序算法的時間近似值(例如 n^2 , n*2 , nlogn )

函數(shù)式編程 2023-07-28 09:35:16
新的修改選擇排序算法(在某些情況下優(yōu)于插入排序)與標(biāo)準(zhǔn)選擇排序算法類似,但它只在 Array 中搜索最小值,而是在一次迭代中搜索最小值和最大值。然后它將最小值交換到數(shù)組的開頭,將最大值交換到數(shù)組的末尾。遞增start_pointer、遞減end_pointer,然后再次迭代。我認為對 N 大小的數(shù)組進行排序所需的時間復(fù)雜度是:N + (N-2) + (N-4) + (N-6) + ... + 1。有人可以給我這個公式的近似值嗎?我將不勝感激。public static void DoubleSelectionSort(int[] Array, int startpos, int endpos) {    /*Double Selection Sort Algorithm , made by Milan Domonji 1986 , MilanDomonji@yahoo.com*/    while(startpos < endpos) {        int min = Integer.MAX_VALUE;        int max = Integer.MIN_VALUE;        int minpos = startpos;        int maxpos = endpos;        for(int i = startpos; i <= endpos; i++) {            //main loop that finds minimum and maximum from an Array            if (Array[i] <= min) {                min = Array[i];                minpos = i;            }            if (Array[i] >= max) {                max = Array[i];                maxpos = i;            }           }        /* I added missing part of algorithm so it works now (Edited) */        if (maxpos==startpos && minpos==endpos) {            Swap(Array, minpos, maxpos);        }else {             if (maxpos==startpos) {                Swap(Array,minpos,startpos);                Swap(Array,minpos,endpos);                           }else {               Swap(Array,minpos,startpos);               Swap(Array,maxpos,endpos);          }        }        startpos++;        endpos--;  }}private static void Swap(int[] Array, int A, int B) {    int tmp = Array[A];    Array[A] = Array[B];    Array[B] = tmp;}算法對所有時間進行正確排序。
查看完整描述

1 回答

?
忽然笑

TA貢獻1806條經(jīng)驗 獲得超5個贊

如果您需要總和S = N + (N-2) + (N-4) + ... + (N - (N-2))(例如N是偶數(shù)),則它等于S = 2 + 4 + ... + N = 2 ( 1 + 2 + 3 + ... + N/2) = 2 * N/2 * (N/2 + 1)/2 = N/2 * (N/2 +1) =  Theta(N^2)



查看完整回答
反對 回復(fù) 2023-07-28
  • 1 回答
  • 0 關(guān)注
  • 135 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號