Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Occurence of given string in a large text file

 
Raveendran Hs
Greenhorn
Posts: 23
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which is the efficient algorithm to find the occurrence of a given string in a given large text file.
 
James Sabre
Ranch Hand
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hs Raveendran wrote:Which is the efficient algorithm to find the occurrence of a given string in a given large text file.


There are two prime algorithms for doing this - the Knuth-Morris-Pratt algorithm and the Boyer-Moore algorithm. Both are fairly easy to implement and Google will provide the details. In this case I would probably use the Knuth-Morris-Pratt algorithm since it requires no backtracking.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic