...

/

Complexity Analysis

Complexity Analysis

Let's discuss how fast binary search is and how much memory it uses.

We'll cover the following...
Q

What will be the space complexity for binary search in terms of Big O notation?

A)

O(log_2 \space n)

B)

O(2 ^ n)

C)

O(1)

D)

O(n ^ 2)

Q

What will be the time complexity for binary search in terms of Big O notation?

A)

O(log_2 \space n)

B)

O(2 ^ n)

C)

O(n)

D)

O(n ^ 2)

Time complexity

The essential property of binary search is to reduce the search area to, nearly, half of the original size.

Suppose we have n` elements in our search array. On each iteration, we’re down to ​ 2n elements. The search area keeps halving from n to ​2​n, to 4​n, to 8n, and so on, ...