An open API service indexing awesome lists of open source software.

https://github.com/0xprinc/huff_BinarySearch


https://github.com/0xprinc/huff_BinarySearch

Last synced: 6 months ago
JSON representation

Awesome Lists containing this project

README

        

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.

# to-do list
1. Optimising this contract
2. Writing more test contracts