J'ai écrit ce code pour moi (ce n'est pas un travail à domicile) Je veux savoir est-ce correct? Merciécrire un algorithme avec Θ (nlogn)
algorithme avec le temps Θ (nlogn), qui peut fournir un tableau de n membres pour déterminer si deux éléments du tableau qui sont égaux à x, puis retournent les éléments
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: il semble y avoir un nouveau courant sur SO, vous obtenez des downvotes sans aucune raison:/Vraiment énervant! –