binary search

From The K Language Wiki
Revision as of 06:14, 9 July 2022 by Promovicz (talk | contribs) ("Better category ordering, add redirects to categories, fix pseudo-adverb categories")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Binary search
x'y

Binary search performs a binary search for y in a list x, assuming x is sorted in ascending order. It returns the smallest index i such that y would sort after (or matches) x[i], or -1 if no such index exists.

binary search is right atomic.

  0 2 4 6 8 10'5
 2
   0 2 4 6 8 10'-10 0 4 5 6 20
 -1 0 2 2 3 5