https://github.com/0xprinc/huff_BinarySearch
https://github.com/0xprinc/huff_BinarySearch
Last synced: 6 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/0xprinc/huff_BinarySearch
- Owner: 0xprinc
- License: unlicense
- Created: 2023-03-02T17:26:47.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-03-08T16:07:48.000Z (about 2 years ago)
- Last Synced: 2024-05-18T18:03:00.693Z (12 months ago)
- Language: Solidity
- Size: 285 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-huff - huff-binarySearch
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