Prepare
Practice
Interview
Aptitude
Reasoning
English
GD
Placement papers
HR
Current affairs
Engineering
MCA
MBA
Online test
Login
Complexity of Binary Search Algorithm - O(log n) - Data Structure
Home
>>
Category
>>
Programming Language (MCQ) questions
>>
Data Structure
Q. What is the Complexity of Binary Search Algorithm?
- Published on 25 Aug 15
a.
O(n)
b.
O(log n)
c.
O(n2)
d.
O(n log n)
ANSWER: O(log n)
Related Content
Networking (
207
)
Database (
97
)
C programming (
58
)
Software Engineering (
28
)
SQL (
5
)
HTML (
74
)
Web Technologies (
11
)
Data Structure (
140
)
Operating System (
96
)
Java (
25
)
Oracle (
5
)
C++ (
50
)
Algorithms (
7
)
PL/SQL (
13
)
JavaScript (
7
)
XML (
0
)
CSS (
1
)
Discussion
Nihal
-Posted on 01 Apr 16
Worst case complexity O (log n)
Best case complexity O( 1 )
Average case complexity O (log n)
Binary search algorithm:
In binary search, the array should be sorted. First, compare the item to be searched with the middle element of the array. If the item is found, then search end successfully. If not the array is divided into two part. First part contains all elements to the left of middle element and the other second part contains all the elements to the right side of the middle element.
Due to sorted array, all the element in the first part will be smaller than the middle element and all the element in the second part will be greater than the middle element. If the item to be searched is less than the middle element, then this item will be in first half otherwise it will be in the second half. This process will be continue till we find the required item or get a subarray which does not have any element.
➨
Post your comment / Share knowledge
Required!
Required!
Invalid Email Id!
Required!
Enter the code shown above:
Please enter the code shown above
(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)
MCQs
English
Tutorials
Download
▲