Re: [理工] 100中央(DS&ALGO)

看板Grad-ProbAsk作者 (想玩音樂)時間14年前 (2012/01/12 20:12), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/4 (看更多)
※ 引述《justbelieve (呆)》之銘言: 我也沒答案 (歹勢) 不過大致上寫的也不多相近 如果以下想法有錯還希望懂的人給予指教謝謝 : http://ppt.cc/hjRU : 因為手頭沒答案 : 想上來跟有寫的or有答案的問一下,順便對 : 1.1寫得很陽春,大致上想法是 : function Search(key x,pointer root) : { : if(root.key == x) then return found; : else if(root的*left不為空){ : then root = root的*left; : Call function Search(x,root); : } : else if(root的*right不為空){ : then root = root的*right; : Call function Search(x,root); : } : else return Null; : } : } : } : 1.2還在想,有類似的考古嗎? 1.2 我不知道是不是像一般的DFS偵測 cycle 程式 but use its data struture 我是寫... color[1...n] = array(); for(i=1 to n){ color[i]=0; } bool isCycleExist(node *root){ if(!root){ return false; } else if(color[root->key]){ return true; } else{ color[root->key] = 1; left = isCycleExist(root->left); right = isCycleExist(root->right); if(left | right){ // 左右 child 至少一個抓到 cycle return true; } else{ reutrn false; } } } : 2.completion order:j1,j2,j6,j3,j9,j7,j5,j4,j8 這邊我寫 j1 j2 j7 j9 j6 j5 j3 j4 j8 我比較疑惑的是 當 arrival time = t+7 此時 j2 執行完畢, 下一個會輪到 j7 但是 j9 在這個時候進入 stack 那這樣是 j9先進入stack , 隨即 j9 被取出先執行 還是 j7 先被取出執行 then j9再進入 stack ? 不知道這一題有無說明這點@@ : 3.2 AVL tree: 5 : / \ : 3 8 : / \ / \ : 2 4 6 9 : \ : 7 : 5和6有類似的考古or有大大可以分享一下解答嗎? 5.1 感覺可以用類似離散spaning tree的定理證 不過我還沒想到怎麼走這條 (歹勢) : 7.2 最少乘法數:5610 : (((A1A2)A3)A4)A5 : 不知道有沒有計算錯,怎麼感覺越算越小? 我也是算這個答案 -- No time to pray.... -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.128.126.145

01/12 21:40, , 1F
m大我有把第2題過程寫在我原文最下面,你看一下,來討論
01/12 21:40, 1F
文章代碼(AID): #1F3iv9Ij (Grad-ProbAsk)
文章代碼(AID): #1F3iv9Ij (Grad-ProbAsk)