A good way to solve this problem would be:
1. Finding the recurrence relation
For each call to f we have time complexity T(N). Each call contains:
- A constant amount of work
C: sum++, comparison N > 1, recursive calling overhead, etc.
- 2 recursive calls to
f, each with time complexity T(N / 2).
Thus the recurrence relation is given by T(N) = 2T(N/2) + C.
2. Finding a solution by inspection
If we repeatedly substitute T(N) into itself, we can see an emerging pattern:

What is the upper limit of the summation, m? Since the stopping condition is N > 1, after repeated substitutions the requirement would be

Thus the summation equals (dropping the round-down, and the constant C because it is simply multiplicative):

3. Proof by induction
Base step: test if the summation result is correct for the lowest possible value of N, i.e. 2:

The result is consistent.
Recurrence step: confirm that if the summation is correct for N / 2, it is also correct for N:

Which is exactly our original recurrence relation.
Hence by induction, the summation result is correct, and T(N) is indeed Ө(N).
4. Numerical testing:
We can write code to confirm our result if needed:
function T(n) {
return n > 1 ? 2 * T(floor(n/2)) + 1 : 1;
}
Results:
N T(N)
-------------------------
2 3
4 7
8 15
16 31
32 63
64 127
128 255
256 511
512 1023
1024 2047
2048 4095
4096 8191
8192 16383
16384 32767
32768 65535
65536 131071
131072 262143
262144 524287
524288 1048575
1048576 2097151
2097152 4194303
4194304 8388607
8388608 16777215
16777216 33554431
33554432 67108863
67108864 134217727
134217728 268435455
268435456 536870911
536870912 1073741823
1073741824 2147483647
Graph:
