我对大 O 的了解是有限的,当对数项出现在方程中时,我会更加困惑。
谁能给我简单解释一下什么是 O(log n)
算法? 对数从何而来?
这个问题是在我试图解决期中练习题的时候突然冒出来的:
Let X(1..n) and Y(1..n) contain two lists of integers, each sorted in nondecreasing order. Give an O(log n)-time algorithm to find the median (or the nth smallest integer) of all 2n combined elements. For ex, X = (4, 5, 7, 8, 9) and Y = (3, 5, 8, 9, 10), then 7 is the median of the combined list (3, 4, 5, 5, 7, 8, 8, 9, 9, 10). [Hint: use concepts of binary search]