Skip to content

Commit

Permalink
binary search documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
priyankchheda committed Feb 21, 2019
1 parent 518441e commit b280e52
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions search/binarysearch.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
// Package search is an implementation of various search algorithm in GoLang
package search

// BinarySearch is the most efficient searching algorithm having a run-time
// complexity of O(log2 N). This algorithm works only on a sorted list of
// elements.
//
// Binary search begins by comparing the middle element of the list with the
// target element. If the target value matches the middle element, its position
// in the list is returned. If it does not match, the list is divided into two
// halves. The first half consists of the first element to middle element
// whereas the second half consists of the element next to the middle element
// to the last element.
func BinarySearch(arr []int, value int) int {
start := 0
end := len(arr) - 1
Expand Down

0 comments on commit b280e52

Please sign in to comment.