Why does this O(N^2) algorithm run so quickly?
问题 This algorithm is O(n 2 ), however it runs in less than a second. Why is it so quick? public class ScalabilityTest { public static void main(String[] args) { long oldTime = System.currentTimeMillis(); double[] array = new double[5000000]; for ( int i = 0; i < array.length; i++ ) { for ( int j = 0; j < i; j++ ) { double x = array[j] + array[i]; } } System.out.println( (System.currentTimeMillis()-oldTime) / 1000 ); } } EDIT: I modified the code to the following and now it runs very slowly.