Delicate Data Structures

來源:互聯網
上載者:User

標籤:

 

1. Fenwich Tree

  樹狀數組提供複雜度為O($lg n$)的連續地區求和查詢以及對指定元素的修改操作。

 1 #define N 1024 2 #define lowbit(x) (x&(-x)) 3  4 int arr[N]; 5  6 void add(int idx,int delt) 7 { 8     while (idx<N) { 9         arr[idx] += delt;10         idx += lowbit(idx);11 }12 13 int sum(int idx)14 {15     int val = 0;16     while (idx>0) {17         val += arr[idx];18         idx -= lowbit(idx);19     }20     return val;21 }

  這裡,lowbit是一個有參宏定義,用於提取整型數x的最低非零位。類似的定義方式還有:

# define divAndCeil(x,y) ((x+y-1)/y)

 

2. Skip List

  跳錶,一種隨機化資料結構,僅依賴於並聯的鏈表,效率可比擬二叉搜尋樹。

  查詢、插入、刪除的平均時間都是O($lgn$),詳見 wikipedia 。

  沒時間分析演算法、編碼實現了。真心沒時間了。T_T

 

3. Trie Tree

  字典樹利用串的公用首碼節約記憶體,加快檢索速度。

  根節點無字母;從根節點到某節點的路徑上所有字母構成的序列為該節點對應的單詞。

  樹的結構可以用兒子鏈表(或數組)實現,也可以用 left-child, right-sibling tree 。

 

Delicate Data Structures

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.