Trees Flashcards

1
Q

What is Breadth First traversal?

A

Breadth-First traverses each level before moving onto next levels

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is Depth First traversal?

A

Depth First makes its way to the bottom level first and works back up

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the programmatic difference between Breadth-First and Depth First?

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

If you are asked a traversal question regarding width, what traversal method would you use?

A

A Breadth-First method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the difference between a Binary Tree and a Binary Search Tree?

A

A Binary Search Tree requires the left node to be less than the parent and the right node to be more.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you find the min or max in a BST?

A

To find the min, while node.left, set node to node.left, then return the node.val

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the 4 steps in a function to find the lowest common ancestor of 2 nodes in a BST?

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly