
int N; int i; for ( i = 0; i < N; i++ ) do_marker(); 
The following diagram shows the number of times that do_marker() is executed when N = n:
i = 0 1 2 3 ... n # do_marker(): 1 1 1 1 ... 1 
Count the number of 1's to find the number of times that do_marker() is executed....
Clearly: running time of this loop is equal to N
int N; int i, j; for ( i = 0; i < N; i++ ) for ( j = 0; j < N; j++ ) do_marker(); 
The following diagram shows the number of times that do_marker() is executed when N = n:
i = 0 1 2 3 ... n j = 0 0 0 0 ... 0 1 1 1 1 ... 1  2 2 2 2 ... 2  V n n n n ... n 
Count the number of red indices to find the number of times that do_marker() is executed....
Clearly: running time of this loop is equal to N^{2}