cairo-vm
cairo-vm copied to clipboard
Use binary search for find_element functions
I was looking at the hint more closely and realized that there might be no point in applying a binary search. The search works by iterating over an array of { key, value } type items.
| key0 | val0 ... | key1 | val1 ... | key2 | val2 ... | ...
^ keys that are observed
To recover these keys we have to look at the whole chunk of memory where the array is allocated. This already takes O(n) time and the search can be done while building the array.
To recover these keys we have to look at the whole chunk of memory where the array is allocated. This already takes O(n) time and the search can be done while building the array.
It's not clear to me that you need to access all keys here. Is it not supposed to be sorted in the cited hint?
To recover these keys we have to look at the whole chunk of memory where the array is allocated. This already takes O(n) time and the search can be done while building the array.
It's not clear to me that you need to access all keys here. Is it not supposed to be sorted in the cited hint?
Yeah, I've been giving it some more thought and I think it can be done