Week 4 - Binary Search Tree (BST) Flashcards

1
Q

What is Key Idea 1 behind using a Binary Search Tree (BST)?

A

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.

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

Why is keeping a small height important in BSTs?

A

A small height reduces the number of steps needed to traverse the tree, allowing for faster access to elements and better overall performance.

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

What is Key Idea 2 behind Binary Search Trees?

A

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.

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

Can a Binary Search Tree contain duplicate values?

A

In the simplified version of BSTs, no duplicate values are allowed. Each value is unique and appears only once in the tree.

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

What does In-order Traversal (LNR) stand for?

A

LNR stands for:

  1. Left subtree
  2. Node (current node)
  3. Right subtree
    It processes the left, then current, then right recursively.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the steps in In-order Traversal?

A
  1. Recursively traverse the left subtree
  2. Visit the current node
  3. Recursively traverse the right subtree
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a common use case for In-order Traversal?

A

In-order traversal is used when you want to process or display a BST’s data in sorted (ascending) order.

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

What is the result of In-order traversal on a binary search tree?

A

It produces a sorted sequence of values in ascending order, since BST properties ensure left < node < right.

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

What does Post-order Traversal (LRN) stand for?

A

LRN stands for:

  1. Left subtree
  2. Right subtree
  3. Node (current node)
    It processes all children before the parent
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the steps in Post-order Traversal?

A

1.Recursively traverse the left subtree

  1. Recursively traverse the right subtree
  2. Visit the current node
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a common use case for Post-order Traversal?

A

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

How is Post-order Traversal different from In-order?

A

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).

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