apple / swift-algorithms

Commonly used sequence and collection algorithms for Swift
Apache License 2.0
5.97k stars 443 forks source link

Binary search function for collection or array #181

Open daihan054 opened 2 years ago

daihan054 commented 2 years ago

In c++ there has a stl function named as lower_bound which works as binary search. But in swift there has no such function. Could you please add it?

xwu commented 2 years ago

partitioningIndex(where:) is a slight generalization of a binary search, and is an O(log n) operation for random-access collections; O(n) otherwise.

Dhandeep10 commented 1 year ago

Hey! I got how to do this and have successfully written code for the required lower bound and upper bound. Can you please help me what i have to do to create a pull request? And where I have to paste this code. (as I am new to open source)