binary_search: Binary Search

Description Usage Arguments Value Examples

View source: R/binary_search.R

Description

The function applies the generic binary search algorithm to search if the value x exists in the lst, and returns a vector contains: TRUE/FAlSE depends on whether the x value has been found, x value, and x position index in lst

Usage

1
binary_search(x, lst)

Arguments

x

: numeric value less than 1000.

lst

: sorted vector of numerics

Value

a list: First character represents a logical value (TRUE/FALSE). Second character represents a numeric value of x. Third character represents a numeric in range of 1 to length(lst) where NA indicates the element is not in the list

Examples

1
2
3
4
5
binary_search(4, c(1,2,3,4,5,6))
c('TRUE','4','4')

binary_search(5, c(10,100,200,300))
c('FALSE','5','0')

UBC-MDS/mlist_R documentation built on May 7, 2019, 7:14 p.m.