How to work out the time complexity of this algorithm, both O() and Ω().
This nested loop is different from the common nested loop analysis, because m and n are independent such that |A| = n ≥ |B| = m.
What I am thinking is for each iteration, it will run O(1) time.
For the times of iteration (line 3 and line 4), it should be
m + (m − 1) + ... + 1 + (n - m) = O(m^2 + n)
Therefore, the time of this algorithm should be O(m^2 + n) and so is Ω.
However, the solution tells me it should be O(mn) and Ω(mn). I cannot figure it out how to get that answer.