binarySearch(A, n, num)

This function find number in array (sorted) using binary search
1.1K Downloads
Updated 31 Mar 2016

View License

Syntax: [index] = binarySearch(A, n, num);
Inputs: A: Array (sorted) that you want to search
n: Length of array A
num: Number you want to search in array A
Outputs: index: Return position in A that A(index) == num or -1 if num does not exist in A
Complexity: O(1) best-case performance
O(log_2 (n)) worst-case performance
O(1) auxiliary space
Author: Trong Hoang Vo
hoangtrong2305@gmail.com
Date: March 31, 2016

Cite As

Trong Hoang Vo (2026). binarySearch(A, n, num) (https://www.mathworks.com/matlabcentral/fileexchange/56271-binarysearch-a-n-num), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2014a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Shifting and Sorting Matrices in Help Center and MATLAB Answers
Tags Add Tags
Version Published Release Notes
1.0