[理工] [資結]99交大資聯

看板Grad-ProbAsk作者 (yauiwen)時間16年前 (2010/03/17 11:34), 編輯推噓7(708)
留言15則, 7人參與, 最新討論串1/1
4.Assume that a max heap is implemented in an array and we input the set of numbers as "31,41,59,26,53,58,97." (9)What's the final sequence of numbers in an array? 31 , 31 41 41 59 59 59 59 / => / , / \ => / \ , / \ , / \ => / \ , 41 31 31 59 31 41 31 41 31 41 53 41 / / \ / \ 26 26 53 26 31 59 59 59 59 97 / \ / \ / \ / \ / \ 53 41 => 53 58 , 53 58 => 53 97 => 53 59 / \ / / \ / / \ / \ / \ / \ / \ / \ 26 31 58 26 31 41 26 31 41 97 26 31 41 58 26 31 41 58 # 我最後的答案是(97,53,59,26,31,41,58) 可是選項裡沒這個答案 (10)Suppose that we perform "DeleteMax" that removes the maximal number from the max heap and put this number in the last element od the array.What's the sequence of numbers in the array after we execute the first DeleteMax operation. 58 59 / \ / \ remove 97 => 53 59 => 53 58 / \ / / \ / 26 31 41 26 31 41 我的答案是(59,53,58,26,31,41,97) 選項裡也沒有.. 是我哪裡做錯了嗎? 凡請指正 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.115.52.122

03/17 11:43, , 1F
用bottom-up方式做,就有答案可以選了
03/17 11:43, 1F

03/17 11:44, , 2F
推樓上
03/17 11:44, 2F

03/17 11:45, , 3F
41.58.31 ?
03/17 11:45, 3F

03/17 12:01, , 4F
謝謝! 了解
03/17 12:01, 4F

03/17 12:42, , 5F
這題 我用TOP DOWN 跟你算一樣 但是我選最相近解
03/17 12:42, 5F

03/17 12:42, , 6F
被我猜中 哈哈哈哈哈阿
03/17 12:42, 6F

03/17 12:46, , 7F
順便問一下,如果不是選擇題,要用哪種方式作答? 謝
03/17 12:46, 7F

03/17 12:47, , 8F
buttom-up 因為他說在array裡了
03/17 12:47, 8F

03/17 12:49, , 9F
誰規定在陣列就要用BUTTOM UP 但是其實BUTTOM UP比較好
03/17 12:49, 9F

03/17 12:51, , 10F
他說用insert就TOP DOWN
03/17 12:51, 10F

03/17 12:51, , 11F
題目都會有關建字
03/17 12:51, 11F

03/17 14:27, , 12F
同意樓上,這種是暗示的,沒有明定,但不這樣寫就錯
03/17 14:27, 12F

03/17 14:30, , 13F
題目寫著array, 若你用insert去做, 還要再多一些外部
03/17 14:30, 13F

03/17 14:31, , 14F
空間來輔助, 這是較不符合題目給應答者暗示的
03/17 14:31, 14F

03/17 14:56, , 15F
agree
03/17 14:56, 15F
文章代碼(AID): #1Be4snPE (Grad-ProbAsk)