Anagrams1.java
Anagrams1_sort.java
name function ---- -------- constant O() e.g. basic access one element in array or hash-table if the operation simply always requires same time Zs., then it's O() logarithmic O() e.g. one binary search linear O() e.g. make a copy of file O(N*log(N)) e.g. above multiple binary searches polynomial quadratic O() e.g. above multiple linear searches cubic O() e.g. matrix-multiplication exponential O() e.g. Tower(s) of Hanoi problem
+
%
A[i]
break
continue
x = 3 + x; if( x < y && x < 0 ) y = x;
x++
for( j = 0; j < n; j++ ) A[i][j] = 0;
j = 0; confirm j < n A[i][j] = 0; j++; // j = confirm j < n A[i][j] = 0; j++; // j = confirm j < n A[i][j] = 0; j++; // j = . . . confirm j < n A[i][j] = 0; j++; // j = confirm j < n A[i][j] = 0; j++; // j = confirm j < n (stop)
<=
but only in cases with a fixed/constant sequence of actions
x = y + 3;
System.out.println(MATERIAL)
A[i][j] = 0;
j < n;
j++
n * Θ(1) := :=
... sum = 0; // Θ(1) + for ( i = 0; // Θ(1) + i < n*n; i++ ) // Θ(n²) * for ( j = 0; j < n; j++ ) // Θ(n) * sum++; // Θ(1)
... sum = 0; // Θ(1) + for ( i = 0; i < n*n; i++ ) // Θ(n²) * for ( j = 0; j < i; j++ ) // Θ(?i?) * sum++; // Θ(1)
i
i < n*n
i ≤ n*n
... sum = 0; // O(1) + for ( i = 0; i < n*n; i++ ) // O(n²) * for ( j = 0; j < i; j++ ) // O(n*n) * sum++; // O(1)
... sum = 0; // Θ(1) + for ( i = 0; i < n*n; i++ ) // Θ(n2) * for ( j = 0; j < i; j++ ) // Θ(n2/2) * sum++; // Θ(1)
if
index_smallest = 0; for( j = 1; j < n; j++ ) if( A[j] < A[index_smallest ) index_smallest = j;
else
index_smallest = 0; for( j = 1; j < n; j++ ) if( A[j] < A[index_smallest ) index_smallest = j; else index_smallest = index_smallest