b8*******@yahoo.com (b83503104) wrote:
I have a big text file with millions of lines, and given any number k
as input, I want to output line k. What is the most efficient way to
do this, other than checking end-of-line k times?
For a one-shot run, that _is_ the most efficient way. If you run this
search repeatedly, and you know that the text file is not going to
change, you can create an index file (or even an index in memory, if you
want to waste several millions of bytes on it). If you run this search
repeatedly, and the text file does change, probably the most efficient
solution is to get the program that changes it to also update the index.
Basically, you'd be turning your text file into a database of sorts.
Richard