我有一个嵌套的数字列表,其中有n个行和列,每个行和列中的每个数字都在增加。
例如:
db.communications.aggregate([
{ "$unwind": "$messages" },
{ "$lookup": {
"from": "users",
"localField": "messages.authorId",
"foreignField": "_id",
"as": "messages.authorId"
}},
{ "$unwind": "$messages.authorId" },
{ "$group": {
"_id": "$_id",
"messages": { "$push": "$messages" },
"type": { "$first": "$type" },
"title": { "$first": "$title" },
"receivers": { "$first": "$receivers" }
}}
])
我需要使用二进制搜索来查找元素是否在列表中,并且算法最坏情况下的时间复杂度必须为O(n)。
我有此代码:
A = [[19, 30, 31, 45, 57],
[25, 32, 32, 51, 69],
[33, 35, 38, 58, 78],
[34, 49, 67, 84, 102],
[44, 54, 73, 90, 115]]
我认为这段代码的时间复杂度为O(n log n),但我对此不确定。那么这段代码的实时复杂度是多少?