How do you calculate a large binary search algorithm?

I am looking for mathematical proof, not just an answer.

+5
source share
2 answers

binary search recurrence relation is (in the worst case)

T(n) = T(n/2) + O(1)

Using the Main Theorem

enter image description here

  • n is the size of the problem.
  • a is the number of subtasks in recursion.
  • n / b is the size of each subtask. (It is assumed here that all subtasks are essentially the same size.)
  • f (n) is the cost of the work performed outside of the recursive calls, which includes the cost of dividing the problem and the cost of merging the solutions with the subtasks.

Here a = 1, b = 2 and f (n) = O (1) [Constant]

f (n) = O (1) = O (n log b a)

= > T (n) = O (n log b a log 2 n)) = O (log 2 n)

+11

: , , . n log 2 (n) , :

2 · 2 ·... · 2 · 2 = 2 x ≤ n ⇒ log 2 (2 x) = x ≤ log < > 2 > ()

x . O (1) O (log n) .

+7

All Articles