This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def binarySearch(sortedArray: list, searchFor, prevMiddle = 0) ->int: | |
middle = int(len(sortedArray)/2) | |
if(sortedArray[middle] == searchFor): | |
return prevMiddle + middle | |
elif(sortedArray[middle] < searchFor): | |
#should keep a track of left index of array | |
prevMiddle += middle | |
return binarySearch(sortedArray[middle:], searchFor, prevMiddle) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Trie: | |
trie = None | |
END_WORD = '~END~' | |
def __init__(self): | |
self.trie = {} | |
def add(self, word): |