Skip to content

0xprinc/huff_BinarySearch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages