看板 Grad-ProbAsk 關於我們 聯絡資訊
(1)Find the average-case height of a binary tree with five nodes. You have to consider all possible binary trees with five nodes. Assume that each of these is equally likely to occur. (2)Approximate the best-case height of a binary tree with n nodes. (以big-O表 示) 請問這兩題怎麼解? 請高手幫個忙 囧RZ -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 124.9.199.198 ※ 文章網址: https://www.ptt.cc/bbs/Grad-ProbAsk/M.1422107134.A.69C.html ※ 編輯: sads333 (124.9.199.198), 01/24/2015 21:47:07
GuardmanMart: (2)best case相當於高度最小化=complete B.T,N個no 01/24 22:35
GuardmanMart: des的complete B.T的高度=log(N+1)取上高斯=O(logN) 01/24 22:35
GuardmanMart: (1)5個nodes可以造出來的B.T=(1/6)*C(10,5)=42,其 01/24 22:45
GuardmanMart: 中高度3的有5種、高度5的有2種(畫出來就知道了), 01/24 22:45
GuardmanMart: 其餘皆為高度4,然後把總高度乘一乘加一加之後除以4 01/24 22:45
GuardmanMart: 2就是avg. case了吧 01/24 22:45
JacobSyu: 高度3應該有6種? 可以height=0開始定義? 01/24 23:08
GuardmanMart: 哦對!少算一種,是6種沒錯 01/24 23:25
GuardmanMart: 題目沒給的話感覺自己假設height從0或1開始都ok 01/24 23:27
JacobSyu: 這題是哪間學校的,還不錯! 01/24 23:31
harryron9: 高度5的不只2種吧... 01/25 01:07
GuardmanMart: 好像是耶...一開始沒認真想只下意識想到左斜和右斜 01/25 01:47
GuardmanMart: ,2^4 !? 01/25 01:47
JacobSyu: 哈 我也是.... 01/25 09:50
JacobSyu: 8種? 01/25 14:38
GuardmanMart: 我的想法是root之後的每個level都能選左或右,所以2 01/25 14:46
GuardmanMart: ^4 01/25 14:46
PuffinApp: 印象台大有考過...15分 01/25 17:25
PuffinApp: 總共好像...42? 01/25 17:26
JacobSyu: 謝謝 確實16種 01/25 17:26