演算法作業05
第1題: Heap Sort
1-1. 下圖為Max Heap。Heap Sort的每一回合,會將Heap的最大值刪除後,又恢復為Heap。請畫出第一回合恢復的過程
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
1-2. 投影片69頁的公式如下,請解釋此公式的含意。
是目前的樹高,是樹的整體高度
就是跑到底所需要的成本
是因為有左右兩個子節點,所以要
就是枚舉從到,把第層所有節點要往左往右跑到層的總成本加起來
第2題: Problem平均的Lower Bound
下圖為二元樹。參考投影片77頁,請算出二元樹的External Path Length,以及葉子平均深度。
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
External Path Length
葉子平均深度
Sorting problem reduces to Convex Hull Problem
請說明,若要排序五個數字:4,1,3,2,5,如何轉為Convex Hull Problem後,完成排序。
如果將每個數字轉成二維的點
在二維平面上會呈現一個拋物線(左邊起來的是負數)
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
再對這筆資料做凸包就會求出排序了
第4題:圓型打字機
解題思路
先寫一個atob
計算從字母甲到字母乙的距離(比較漂亮)
然後再模擬並記錄轉輪盤的過程成本
最後再加上輸出的成本
程式碼
測試輸出輸入的畫面截圖
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
花費時間
15分鐘
完成程度
完全自己解出
第5題:跳到最後
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
解題思路
程式碼
測試輸出輸入的畫面截圖
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
花費時間
15分鐘
完成程度
完全自己解出
第6題:由各行的和與各列的和求矩陣
解題思路
一開始先把每個丟進
初始:
|
8 |
6 |
8 |
5 |
8 |
6 |
8 |
7 |
0 |
0 |
0 |
10 |
0 |
0 |
0 |
維護每的數字,從左邊開始將數字往下壓
如果不夠就到下一個,太多就丟到下一
跑完
|
8 |
6 |
8 |
5 |
5 |
0 |
0 |
7 |
3 |
6 |
8 |
10 |
0 |
0 |
0 |
跑完
|
8 |
6 |
8 |
5 |
5 |
0 |
0 |
7 |
3 |
4 |
0 |
10 |
0 |
2 |
8 |
結束
附上我想的過程的畫畫(沒有按照順序畫,都在亂畫)

程式碼
測試輸出輸入的畫面截圖

花費時間
44分鐘
完成程度
完全自己解出
第7題:心得
已填