This repository contains the implementation of binary search algorithm written in HUFF for EVM chains.
Given a sorted array, the Binary Search Algorithm searches for a specific element in a sorted list or array in an efficient way.
pseudo-code for binary search is as follows:
// we are gonna use the two pointer for this algorithm
// left pointer points the start of the array
// right pointer points the end of the array
while(left pointer <= right pointer){
// middle pointer will be the average of the left and right pointer
middle = left + (right - left)/2
if(middle element == num){
return middle index;
}
else if(num > middle element){
left = middle + 1;
}
else if(num < middle element){
right = middle - 1;
}
}
I have also included the implementation of the binary search in solidity.
- Optimising this contract
- Writing more test contracts