Professional Documents
Culture Documents
2019/12/02
2
y=predecessor[x]
Key points: y<x
y
– y is in x’s left subtree (y1: the maximum in x’s left subtree)
y – x is in y’s right subtree (y2 : the maximum in x’s ancestors)
x
– y1< y2 first check the existence of y1, then y2
y
y y
• Practice
• Assume the input is drawn from a uniform distribution,
say, between [a,b)
5
Answer
BUCKET-SORT(A,n)
for i=1 to n
insert A[i] into list B[floor(n*( A[i]-a ) / (b-a) )]
for i=0 to n-1
sort B[i] with insertion sort
concatenate the lists B[0], B[1],…,B[n-1] together in order
6
Batch code 例子
• mean.exe
• 計算陣列的平均值
• Input: [n, min, max, rs]
• Output: the mean of array
• run_all.bat
1. 建立一個輸入檔 input.txt
2. feed 這個輸入檔 input.txt 給執行檔 mean.exe
3. 將結果輸出到 output.txt