Skip to content

DEV-Archie/P1-BinarySearch

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

Binary Search

Given a sorted array arr[] of n elements, write a function to search a given element x in arr[].

A simple approach is to do a linear search. The time complexity of the Linear Search algorithm is O(n). Another approach to perform the same task is using Binary Search.

Binary Search:

Search a sorted array by repeatedly dividing the search interval in half. Begin with an interval covering the whole array.
If the value of the search key is less than the item in the middle of the interval, narrow the interval to the lower half.
Otherwise, narrow it to the upper half. Repeatedly check until the value is found or the interval is empty.

Input:

arr[] = { 2, 3, 4, 10, 40 }
ValueToFind = 10

Output:

Index = 3

Time Complexity:

O(log n)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%