卷別
資料結構與演算法(A)
選擇國立臺灣大學 2022 · 考試 · 第 10 題
考科演算法
(5 points) Consider an integer array of size with elements , where the first elements are positive and the other elements are negative. The following algorithm calculates correctly by calling . What loop invariant is maintained for the while loop of the algorithm?
COMPUTE-P(A, len)
1 if A[1] < 0 return 0
2 left = 1, right = len
3 while left < right
4 m = ceiling((left + right) / 2)
5 if A[m] > 0
6 left = m
7 else
8 right = m - 1
9 return left
- (A)
- (B)
- (C)
- (D)
- (E)none of the other choices