My idea would be go to the last block ( say each block is made of 4K pages ) and check whether it contains all the n lines. You can repeatedly read the blocks from the end of the file and stop at a point where all the n blocks are read.
 
This is just my vague thought.
 
You are free to ignore this idea or you can ping me back if you want to know more about this idea.
 
regards
Arunachalam.

 
On 8/9/06, deadlock <[EMAIL PROTECTED]> wrote:

Given a file (can be a huge file) , write the code to extract the last
'n' lines of the file.

what kind of logic efficient here...??
I mean is it like going at the end of file and then reading from there
until we find n number of newline characters.
or
we can have two pointers 1st pointing at the n'th line from starting
and the second ptr pointing at starting. and then moving each pointer
one line by one line. when the fast pointer reaches at the EOF. Then
start reading all the lines from the slow pointers until EOF is
reached.

Is there any other efficient way of doing it. Please answer with proper
implementation details

Thanks.
deadlock







--
===================================
want to know more about me
http"//ww.livejournal.com/users/arunachalam
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---

Reply via email to