weston-bailey / binary-search-tree-lesson

🌳

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Binary Search Tree 🌴

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!

Data structures that rely on nodes

...and a good order to study them in.

  1. Linked lists -- introduction to node based data structures
  2. Binary Search Trees -- more complex algorithm for sorting nodes based on their value
  3. N-ary Trees -- Trees that can have up to n children
  4. Tries -- N-ary tree that represents relationships between nodes (frequently used for storing words/auto completion lookup)
  5. Graphs -- any node can be linked to any other node in this data structure, are often expressed in either adjacency lists or adjacency matrices

Challenges:

    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

Additional Challenges from Leetcode:

Links

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:

https://visualgo.net/en/bst

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

Here is a visual representaion of a Binary Search Tree

BST

Here is a visual representation of a Trie

Trie

tags: lessons

About

🌳


Languages

Language:Python 100.0%