Rainbow Search ~ Searching Algorithm

Rishub Kumar
1 min readApr 13, 2022

--

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:

Diagrammatic explanation

C++ implementation of Rainbow Search Algorithm

Rainbow Search Function

An example program

--

--

Rishub Kumar
Rishub Kumar

Written by Rishub Kumar

Computer science student, developer. I write my white papers(research) work and about coding stuff here.