1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
#include <iostream>
using namespace std;
int main() {
int foo[10] = {10,1,9,2,3,4,5,8,7,6};
cout << foo[2]; // O(1) constant time?
for (int i = 0; i < sizeof(foo)/sizeof(*foo); i++){ // O(n) linear time?
cout << i;
}
int moo[10] = {20,29,28,27,21,32,45,65};
for (int i = 0; i < sizeof(foo)/sizeof(*foo); i++){ // O(n)2 (square) ?? time?
for (int j = 0; j < sizeof(moo)/sizeof(*moo); j++){
cout << moo[j] + foo[j];
}
}
}
| |