Skip to content

Instantly share code, notes, and snippets.

View MShel's full-sized avatar

MikhailShel MShel

View GitHub Profile
@MShel
MShel / HOLc-42.py
Last active April 18, 2017 17:03
Simple Recursive python binary search
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)
@MShel
MShel / trie.py
Created April 24, 2018 20:45
very simple trie for learning Data Structures
class Trie:
trie = None
END_WORD = '~END~'
def __init__(self):
self.trie = {}
def add(self, word):