Quote:
Originally Posted by spooky69
These are all good suggestions, but there still has to be a more efficient way to search large files.
|
@spooky69
I realized my post was misleading. The 2nd half which you quoted me on was not my recommendation. More suggestions for a cleaner experience.
My real suggestion for finding a word was using a "binary search" algorithm. I aplogoize for those that are not programmers and do not know what that means. Let me give a quick "Laymans summeary"
The binary search is a very very simple search designed for speed and simplicity. Essentially what it does is search through a file/array and cuts the search by half every time reducing the search time by half every time. This gives a mathematical search time of log n.
Here is the algorithm.
What you need to know before the algorithm starts.
* The array size/file size in line numbers
* Must be sorted (dictionaries usally are)
Say we have a file 26 lines long. Each line is the first letter of the alphabit
>We are looking for the word J
MIN = line 1
MAX = line 26
As we do our algorithm the boundary of the MIN/MAX will shrink as we get
closer.
1) Jump to the half the current size(MAX-MIN). We jump to line 13. That is the letter is "M"
2) Compare "J" to "M". "M" is too large so we search down
3) Cut the max size from 26 to 13.
4) Now look at 1/2 the new MIN/MAX(13-1)/2. We get 6.5 so we round to 7.
5) Compare "J" to the MIN+7. That is the letter "G". "J" is larger than "G" so we set the MIN to 7
6) Now take the 1/2 of the new MIN/MAX = (13-7)/2 = 3
) Compare "J" to the MIN+3 = 10 (remember the new min is 7)
7) BINGO we found a match.
If you notice the sequential search would have taken us 10 reads to find "J". The "binary search" algorithm only took 3 reads.
The real hard part is SONY's API since it is not published I don't know if there is a way to jump to line numbers.
__
Cheers
=X=