Skip to content

Instantly share code, notes, and snippets.

@rakeshsukla53
Created November 28, 2015 20:45
Show Gist options
  • Save rakeshsukla53/94ba36b19805c05e53ba to your computer and use it in GitHub Desktop.
Save rakeshsukla53/94ba36b19805c05e53ba to your computer and use it in GitHub Desktop.
BinarySearchTree
http://www.pythontutor.com/visualize.html#code=class+BinarySearchTree%3A+++%23+now+you+can+perform+any+type+of+opertion+on+this+tree%0A+%0A++++def+__init__(self,+value%29%3A%0A+%0A++++++++self.value+%3D+value%0A++++++++self.right+%3D+None%0A++++++++self.left+%3D++None%0A+%0A++++def+insert(self,+data%29%3A++%23+this+will+take+the+value+and+insert+accordingly%0A+%0A++++++++if+data+%3E+self.value%3A%0A++++++++++++if+self.right+%3D%3D+None%3A%0A++++++++++++++++self.right+%3D+BinarySearchTree(data%29%0A++++++++++++else%3A%0A++++++++++++++++self.right.insert(data%29%0A+%0A++++++++elif+data+%3C+self.value%3A%0A++++++++++++if+self.left+%3D%3D+None%3A%0A++++++++++++++++self.left+%3D+BinarySearchTree(data%29%0A++++++++++++else%3A%0A++++++++++++++++self.left.insert(data%29%0A++++++++else%3A%0A++++++++++++self.data+%3D+data%0A++++++++++++%0Aroot+%3D+BinarySearchTree(1%29%0Aroot.insert(2%29&mode=display&origin=opt-frontend.js&cumulative=false&heapPrimitives=false&textReferences=false&py=2&rawInputLstJSON=%5B%5D&curInstr=17