Week 4 - Binary Search Tree (BST) Flashcards
What is Key Idea 1 behind using a Binary Search Tree (BST)?
A large balanced or nearly balanced tree has a small height, which helps keep operations like search, insert, and delete efficient — ideally O(log n) time.
Why is keeping a small height important in BSTs?
A small height reduces the number of steps needed to traverse the tree, allowing for faster access to elements and better overall performance.
What is Key Idea 2 behind Binary Search Trees?
BSTs are structured so that:
The left subtree contains values less than the parent.
The right subtree contains values greater than the parent.
This ordering allows for fast lookup using binary search logic.
Can a Binary Search Tree contain duplicate values?
In the simplified version of BSTs, no duplicate values are allowed. Each value is unique and appears only once in the tree.
What does In-order Traversal (LNR) stand for?
LNR stands for:
- Left subtree
- Node (current node)
- Right subtree
It processes the left, then current, then right recursively.
What are the steps in In-order Traversal?
- Recursively traverse the left subtree
- Visit the current node
- Recursively traverse the right subtree
What is a common use case for In-order Traversal?
In-order traversal is used when you want to process or display a BST’s data in sorted (ascending) order.
What is the result of In-order traversal on a binary search tree?
It produces a sorted sequence of values in ascending order, since BST properties ensure left < node < right.
What does Post-order Traversal (LRN) stand for?
LRN stands for:
- Left subtree
- Right subtree
- Node (current node)
It processes all children before the parent
What are the steps in Post-order Traversal?
1.Recursively traverse the left subtree
- Recursively traverse the right subtree
- Visit the current node
What is a common use case for Post-order Traversal?
It is used when you need to process all descendants of a node before the node itself, such as
- Deleting/freeing memory in trees
- Evaluating expression trees (bottom-up)
How is Post-order Traversal different from In-order?
Post-order: processes children first, then the node
In-order: processes left, then node, then right
Post-order is useful for bottom-up tasks, while in-order is used for sorted output (in BSTs).