Re: [理工] [資結] BST

看板Grad-ProbAsk作者 (Veck)時間11年前 (2012/10/18 01:38), 編輯推噓0(003)
留言3則, 3人參與, 最新討論串1/1
※ 引述《wsx02 ()》之銘言: : give an n-node binary search tree on which both the find-min and find-max : operations can be executed in constant time : 請問有人知道該怎麼解嗎? : 謝謝 Skew 的話,找最小(或最大)在root雖然可以是 O(1) (costant time) 但是另一個最大(最小),會在 leaf 上 所以走訪時還是需要 O(n)的時間 可以用 min-max heap tree root 會是最大(或最小) 其左右子樹的root(及左右兒子)會是最小(或最大) 接著每一層大小大小交錯以此類推 所以 find-min 會在 root 可以在 Constant Time 完成 find-max 會在下一層(Level 1),所以也是 Constant Time 詳細可參考維基 http://goo.gl/aXfqZ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.35.165.67

10/18 02:00, , 1F
min-max heap 也算bst嗎?
10/18 02:00, 1F

10/18 15:29, , 2F
用Deap應該會比較好 左邊是MinHeap 右邊是MaxHeap
10/18 15:29, 2F

10/18 19:35, , 3F
樓上有理,找了一下維基上相關的資料http://goo.gl/nRLQE
10/18 19:35, 3F
文章代碼(AID): #1GVkqh_C (Grad-ProbAsk)