Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculate occurrences of specified word in a large text file

Tags:

java

algorithm

This is an interview question, and should concern about efficiency. How to calculate occurrences of specified word in a large text file? I can only think of indexOf() method in most programming languages, but I don't think that the correct answer.

like image 600
Sawyer Avatar asked Apr 20 '10 03:04

Sawyer


1 Answers

What you want is the Boyer-Moore algorithm. It is the most efficient known general method for this problem.

like image 188
RBarryYoung Avatar answered Oct 10 '22 01:10

RBarryYoung