Rainbow Search ~ Searching Algorithm
I have designed this algorithm to search like rainbow, the concept is simple it search the first and last index at the start then second and last second and so on, in a single loop. The time complexity of this Rainbow Search is O(n) or O(1) in case it has odd number of elements and the element to be searched is at the middle index.
The code of this algorithm can be implemented in variety of languages, but i have choosed C++ to implement it, below is the code of my implementation.
I have provided two code one is just function for a quick insert in your program and one is the example program which you can run and check the algorithm with your test cases.
Diagrammatic concept of Rainbow Search:
C++ implementation of Rainbow Search Algorithm
Rainbow Search Function
An example program