A
UBB · Informatică
202 Raspunsuri multiple

Se consideră algoritmul ceFace(v, st, dr, k), unde v este un vector de n numere întregi sortate crescător (−10^9 ≤ v[1], v[2], ..., v[n] ≤ 10^9), iar k este un număr întreg.

Algoritm 1

Algorithm ceFace(v, st, dr, k)
  If st = dr then
    Return v[st] = k
  EndIf
  mij ← (st + dr) DIV 2
  left ← ceFace(v, st, mij, k)
  right ← ceFace(v, mij+1, dr, k)
  count ← 0
  i ← mij, j ← mij + 1
  While i ≥ st AND j ≤ dr execute
    If v[i] + v[j] = k then
      If v[i] = v[i + 1] then
        count ← count + 1
      EndIf
      i ← i − 1, j ← j + 1
    Else
      If v[i] + v[j] < k then
        j ← j + 1
      Else
        i ← i − 1
      EndIf
    EndIf
  EndWhile
  Return left + right + count
EndAlgorithm

Care dintre următoarele afirmații despre funcție sunt adevărate?

15 / 30