C++ 資料結構1

來源:互聯網
上載者:User

標籤:

O(1)<O(logn)<O(n)<O(nlogn)<O(n2)<O(n3)<O(2n)<O(n!)<O(nn)

 每一個指令,在具體的電腦上運行速度固定。

 

空間複雜度:

long sum1(int n){    long ret = 0;      //4 個位元組                       int* array = (int*)malloc(n * sizeof(int)); //4n個位元組記憶體    int i = 0;   //4 個位元組      for(i=0; i<n; i++)   //沒有分配記憶體    {        array[i] = i + 1;    }        for(i=0; i<n; i++)   //沒有分配記憶體    {        ret += array[i];    }        free(array);         return ret; }

 

long sum3(int n){    long ret = 0;//4個位元組        if( n > 0 )//沒有記憶體    {        ret = (1 + n) * n / 2;     }        return ret;}
long sum2(int n){    long ret = 0; //4個位元組    int i = 0;//4個位元組        for(i=1; i<=n; i++)    {        ret += i;    }        return ret;}

 

C++ 資料結構1

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.