我寫我自己的代碼(它不是一個在家工作),我想知道這是正確的?謝謝寫有Θ(nlogn)的算法
算法的時間Θ(nlogn),它可以提供n個成員的數組,以確定數組中的兩個元素是否等於x,然後返回這些元素
Algorithm Sum(arr,1,n):
MergeSort(arr)
For i<-- 1 to n
m<-- BinarySearch(arr,arr[i],i+1,n)
return m and arr[i]
//end of the sum algorithm
Algorithm BinarySearch(arr,arr[i],p,q)
J<--[p+q/2]
If (arr[j]+arr[i]=x)
Return arr[j]
else if (i<j)
Return BinarySearch(arr,arr[i],p,j-1)
else
Return BinarySearch(arr,arr[i-j],j+1,q)
// end of BinarySearch algorithm
@Justin L:好像有一個新的電流,你沒有任何理由就會降低音量:/真的很煩人! – 2010-06-20 11:24:12