Takeaways
- We may need to navigate the entire height of tree to insert a node --> O(h)
- Breadth-First and Depth-First are two ways to navigate a tree (for searching, printing, updating, etc)
- Breadth-First Search is visiting all nodes in the depth level before moving to the next depth nodes (shallow nodes are visited first)
- Depth-First Search is exploring a branch as far as possible before backtracking
- Both breadth-first and depth-first have to travel to every node, which results in O(n) running time
- A binary search tree is a special type of tree where each node may only have up to 2 children ("left child" and "Right child")
- The left child must be less than it's parent node
- The right child must be greater than it's parent node
- To insert a node into a BST, we have to travel the entire height of the tree (new nodes are always leaf nodes)
- Given n nodes, the height of the tree is O(logn) ("good tree") or O(N-1) ("bad tree")
- We can use recursion to recursively process the left subtree, and then right subtree
Code
January 23rd's code is a tree data structure that represents a shell that will navigate a file system on a computer using commands (cd, ls, pwd, mkdir, etc).You can download the zip, extract it, and then import project with your IDE.
January 30th code represents a BST that holds integers. It is important that you understand how the insert() method works. You can download the zip, extract it, and then import project with your IDE.