1

I have a big text file which contains many English words. However it contains German and French words as well. I need to capture all English words in it.

I reckon, firstly I read all file from the disk and convert it into an array, second I match the all words against unix English word dictionary like here, yet it is not a good solution because of the size of each file. If I do in that way, complexity will be high, and I don't want that.

Do you have any idea how I can do it with Ruby in a simple way?

4

1 回答 1

1

您可以做的第一件事是将英语词典放入一个集合(而不是数组)。这样,查找是 O(1),整体复杂度是 O(N) 而不是 O(NxM)。

于 2013-04-04T07:56:01.667 回答