Computing the running time of a divide-by-4-and-conquer algorithm
The subroutine sub quarters the matrix into four parts. This takes time $f(n)$, and so the running-time of sum (which sums all entries in its input square matrix in a curious divide-and-conquer fashion) satisfies the recurrence
$$ T(n) = \begin{cases} O(1) &amp; n=1 \\ 2T(\lfloor n/2 \rfloor) + 2T(\lceil n/2 \rceil) + f(n) + O(1) &amp; n&gt;1. \end{cases} $$
The subroutine sub is quite simple, and I'm sure you can figure out its running time yourself (though you'll have to be careful about the semantics of list appending in python).