Tree Traversal Flashcards
1
Q
What are the methods of tree traversal?
A
Inorder, preorder, postorder, and level traversal.
2
Q
What is inorder traversal?
A
left, node, right.
3
Q
What is preorder traversal?
A
node, left, right.
4
Q
What is postorder traversal?
A
left, right, node.
5
Q
When to use BFS vs DFS?
A
Use BFS when finding the shortest path in unweighted graphs or level-order traversal.
Use DFS when exploring all possible paths (e.g., backtracking problems, cycle detection).
6
Q
What is a binary search tree?
A
- Standard BSTs have no duplicate values.
- left sub tree must have values less than parent node
- right sub tree must have values greater than parent node.
7
Q
What is the search time complexity of balanced vs unbalanced trees?
A
o(log n) for balanced
and o (n) for unbalanced (like linked list)