[英]rectangular matrix complexity
I have to compute complexity of algorithm which searches an element in a rectangular matrix. 我必须计算在矩形矩阵中搜索元素的算法的复杂性。 It uses divide and conquer. 它使用分而治之。 For square matrix my time functions becomes a*T(n/b)+O(n^2). 对于方矩阵,我的时间函数变为a * T(n / b)+ O(n ^ 2)。 But for rectangular matrix I don't know how to denote the division if it has to be divided into 4 sub matrices. 但是对于矩形矩阵,如果必须将其划分为4个子矩阵,我不知道如何表示该划分。 Will it be a*T(m*n/4) + O(n)? 是a * T(m * n / 4)+ O(n)吗?
You didn't describe you algorithm so it's not possible to answer the question precisely. 您没有描述算法,因此无法精确回答问题。 But I'll try assuming the algorithm is like: 但我会尝试假设算法如下:
m = 1
or n = 1
then process matrix in O(m * n)
time. 如果m = 1
或n = 1
则在O(m * n)
时间内处理矩阵。 m > 1
and n > 1
) divide matrix into four matricies of size not more then [m / 2]x[n / 2]
, where [y]
is a minimal integer not less then y
. 否则( m > 1
和n > 1
)将矩阵分为四个不n > 1
[m / 2]x[n / 2]
矩阵,其中[y]
是不小于y
的最小整数。 O(m * n)
time. 然后“合并”将导致O(m * n)
时间。 In this case recurrent equation for time complexity will be 在这种情况下,时间复杂度的递归方程将是
Lets solve it 让我们解决它
T(m, n) = O(m * n) +
4 * O([m / 2] * [n / 2]) +
4 ^ 2 * O([m / 4] * [n / 4]) +
... +
4 ^ L * O([m / 2 ^ L] * [n / 2 ^ L]), where L = [log(min(m, n))]
T(m, n) = O(m * n + ... + 4 ^ L * [m / 2 ^ L] * [n / 2 ^ L]) =
= O(m * n + ... + 2 ^ L * [m / 2 ^ L] * 2 ^ L * [n / 2 ^ L] =
= O(m * n + ... + m * n (L times)) =
= O(L * m * n) = O(m * n * [log(min(m, n))])
So the answer to your question is 因此,您的问题的答案是
T(m, n) = O(m * n * [log(min(m, n))]), where log
stands for a binary logarithm and [y]
stands for ceil
function. T(m,n)= O(m * n * [log(min(m,n))])),其中log
代表二进制对数, [y]
代表ceil
函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.