Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

binary_search

Binary search algorithm


Description

Search a value in an ordered vector.

Usage

binary_search(x, v, index=FALSE)

Arguments

x

A vector with the data.

v

A value to check if exists in the vector x.

index

A boolean value for choose to return the position inside the vector.

Details

The functions is written in C++ in order to be as fast as possible.

Value

Search if the v exists in x. Then returns TRUE/FALSE if the value is been found.

Author(s)

Manos Papadakis

R implementation and documentation: Manos Papadakis <papadakm95@gmail.com>.

See Also

Examples

x <- sort(rnorm(1000))
v <- x[50]
b <- binary_search(x,v) 
b1 <- binary_search(x,v,TRUE)

Rfast

A Collection of Efficient and Extremely Fast R Functions

v2.0.1
GPL (>= 2.0)
Authors
Manos Papadakis, Michail Tsagris, Marios Dimitriadis, Stefanos Fafalios, Ioannis Tsamardinos, Matteo Fasiolo, Giorgos Borboudakis, John Burkardt, Changliang Zou, Kleanthi Lakiotaki and Christina Chatzipantsiou.
Initial release
2020-09-13

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.