Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.94 KB | None | 0 0
  1. /*
  2.  supondo que o poior caso seja um universo de, por exemplo:
  3.    n = 5.000
  4.    m = 5.000
  5.    
  6.    usando o goto, precisamos de   5.000*5.000        =  25.000.000 comparações
  7.    sem o goto, temos              2*5.000*2*5.000    = 100.000.000 comparações
  8. */
  9.  
  10. /*
  11.   1. usando GOTO
  12.      no pior caso temos O(n*m)
  13. */
  14. possible=0;
  15. for (i=0; i < MAX; i++){                      // n comparações
  16.     for (j=0; j < MAX; j++){                  // m comparações
  17.         if (a[i]!=a[j] && (a[i]+a[j] == x)){
  18.             possible = 1;
  19.             goto found;
  20.         }      
  21.     }
  22. }  
  23. found:
  24. if (possible){ .. }
  25.  
  26.  
  27. /*
  28.    2. usando break + comparações adicionais no flag
  29.       no pior caso temos O(2n*2m)
  30. */
  31. possible=0;
  32. for (i=0; ((i < MAX) && (!found)); i++){        // 2n comparações extras
  33.     for (j=0; ((j < MAX) && (!found)); j++){    // 2m comparações extras
  34.         if (a[i]!=a[j] && (a[i]+a[j] == x)){    
  35.             possible = 1;
  36.             break;
  37.         }      
  38.     }
  39. }  
  40. if (possible){ .. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement