For example, let's say I want to find a specific word or number in a file. The content is in sort order (obvious). Since I want to run a binary search in a file, it seems like a waste of time to copy the entire file to an array and then run a binary search ... I effectively made it a linear time algorithm, I have to spend O (n) time on copying the darn file before I can start my search.
Is there a faster way to do this? Maybe something like lseek that works with strings instead of bytes?
If this is not the case, would I rather just do a linear search (assuming I perform a search once throughout my program)?
source
share