Trees Flashcards
What is Breadth First traversal?
Breadth-First traverses each level before moving onto next levels
What is Depth First traversal?
Depth First makes its way to the bottom level first and works back up
What is the programmatic difference between Breadth-First and Depth First?
- Node children are added to the end of the array in Breadth First
- Node children are added to the beginning of the array in Depth First
If you are asked a traversal question regarding width, what traversal method would you use?
A Breadth-First method
What is the difference between a Binary Tree and a Binary Search Tree?
A Binary Search Tree requires the left node to be less than the parent and the right node to be more.
How do you find the min or max in a BST?
To find the min, while node.left, set node to node.left, then return the node.val
What are the 4 steps in a function to find the lowest common ancestor of 2 nodes in a BST?
- Write a function that takes a root, and 2 nodes as args.
- Then recursively call that function on root.right and root.left.
- If left and right are not null, return the root
- Otherwise return either left or right