These days I needed an algorithm to quickly search for it on an archive of 280000 strings (sorted alphabetically).
So I reckoned that at school I had studied Binary Search.
Allows you to find (or ensure that you are not listed) a key with a fixed and minimum access to the archive.
Access Number: Log2 (TotalNumberKey)
I use the "BinarySearch" Sub recursively
Exponential Search. post #4
So I reckoned that at school I had studied Binary Search.
Allows you to find (or ensure that you are not listed) a key with a fixed and minimum access to the archive.
Access Number: Log2 (TotalNumberKey)
I use the "BinarySearch" Sub recursively
B4X:
Dim Dictionary as List = File.ReadList(File.DirInternal,"MyDict.txt")
Dim MyWord as String = "Hallo"
BinarySearch(MyWord,0,Dictionary.Size-1)
Sub BinarySearch(Word As String, Mn As Int, Mx As Int) As Boolean
Dim MD As Int = ((Mx+Mn)/2)
Dim PM As String = Dictionary.get(MD)
If Mx<Mn Then Return False
If PM=Word Then
Return True
Else if PM.CompareTo(Word)>0 Then
Return BinarySearch(Word,Mn,MD-1)
Else
Return BinarySearch(Word,MD+1,Mx)
End If
End Sub
Last edited: