We are going to be implementing a Binary Tree together! π
Since Trees are a data structure that relies on nodes, I like to think of a Binary Tree as a pre-sorted type of linked list. There is a little algorithmic logic to how a BST stores the data.
To get started head over to BinaryTree.py and check out the classes there. There are method stubs that we are going to fill out together!
...and a good order to study them in.
- Linked lists -- introduction to node based data structures
- Binary Search Trees -- more complex algorithm for sorting nodes based on their value
- N-ary Trees -- Trees that can have up to
n
children - Tries -- N-ary tree that represents relationships between nodes (frequently used for storing words/auto completion lookup)
- Graphs -- any node can be linked to any other node in this data structure, are often expressed in either
adjacency lists
oradjacency matrices
def size():
'''
size() -> int:\n
Calculate the number of nodes in the tree, starting from the root
'''
pass
def height():
'''
height() -> int:\n
Calculate the maximum depth of nodes starting at the root
'''
pass
def get_max():
'''
get_max() -> int:\n
perform depth first search
Calculate the maximum value held in the tree
'''
pass
def get_min():
'''
get_min() -> int:\n
perform depth first search
Calculate the minimum value held in the tree
'''
pass
gitbook:
https://gawdiseattle.gitbook.io/wdi/08-cs/cs-trees-data-structures
imbalanced binary tree:
https://appliedgo.net/balancedtree/
miro board:
https://miro.com/app/board/o9J_lWxUo_o=/
visualgo:
code along built from theses resources:
https://www.tutorialspoint.com/python_data_structure/python_binary_tree.html
https://www.geeksforgeeks.org/binary-tree-set-1-introduction/
https://www.interviewbit.com/blog/n-ary-tree/
https://csanim.com/tutorials/breadth-first-search-python-visualization-and-code