Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Coding puzzle (4)
Message
 
 
À
06/06/2002 09:28:47
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00665368
Message ID:
00665416
Vues:
22
>Einar,
>
>> for i = 1 to alen(myarray)
>> for j = 1 to alen(myarray)
>> if myarray(i)+myarray(j) = X
>> return i,j
>> endi
>> next j
>> next
>
>Your algorithm works but it is quadratic, not linear. A linear algorithm would read each array element once and possibly store one or two values in a variable (hint).
>
>Daniel

Idea:
test = arr[int(k/2)]
if X < test && We don't need to check the rest of the array
   test = arr[int(k/4))
   if X < test && we don't need to check 3/4 of the array
      ...
   endif
endif
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform