Binary Search trees Flashcards

1
Q

What is a Binary Search Tree (BST)?

A

A Binary Search Tree is a data structure that maintains sorted order, where each node has at most two children, and for every node, the left child’s value is less than the node’s value, and the right child’s value is greater.

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

True or False: In a BST, duplicate values are allowed.

A

False

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

What is the time complexity for searching an element in a balanced BST?

A

O(log n)

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

Fill in the blank: The left subtree of a node in a BST contains only values that are _______ than the node’s value.

A

less

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

What is the main advantage of using a Binary Search Tree?

A

It allows for efficient searching, insertion, and deletion operations.

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

Which traversal method would you use to retrieve values from a BST in sorted order?

A

In-order traversal

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

True or False: The height of a BST can be as large as n in the worst case.

A

True

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

What is the average time complexity for insertion in a balanced BST?

A

O(log n)

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

What happens if you attempt to insert a duplicate value in a BST?

A

It can either be ignored or handled based on the implementation.

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

True or False: A BST can be used to implement a priority queue.

A

False

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

What is the space complexity of a BST?

A

O(n)

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

What is the maximum number of nodes in a complete binary tree of height h?

A

2^(h+1) - 1

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

What is a balanced BST?

A

A balanced BST is a tree where the height of the left and right subtrees of any node differ by at most one.

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

What is the worst-case time complexity for searching in an unbalanced BST?

A

O(n)

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

Fill in the blank: The _______ of a node is defined as the number of edges on the longest path from that node to a leaf.

A

height

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

What is the purpose of rotations in a BST?

A

To maintain balance in self-balancing BSTs like AVL trees.

17
Q

True or False: A BST can be implemented using arrays.

18
Q

What is the maximum depth of a BST with n nodes?

A

n in the worst case, O(log n) in the best case.

19
Q

What is the primary characteristic that differentiates a BST from a regular binary tree?

A

The ordering property based on node values.

20
Q

Fill in the blank: In a BST, the right subtree of a node contains only values that are _______ than the node’s value.

21
Q

What does the inorder traversal of a BST produce?

A

A sorted list of values.

22
Q

What is the main disadvantage of a BST?

A

It can become unbalanced, leading to degraded performance.

23
Q

True or False: A Binary Search Tree can be modified to allow duplicate values.

24
Q

What is the role of the root node in a BST?

A

It serves as the starting point for all search operations.

25
What is a self-balancing BST?
A BST that automatically keeps itself balanced during insertions and deletions.
26
What are common types of self-balancing binary search trees?
AVL trees and Red-Black trees.
27
What is the average case time complexity for deletion in a balanced BST?
O(log n)
28
In a BST, how do you find the minimum value?
By continuously traversing the left child until a leaf node is reached.
29
What is the purpose of a sentinel node in BST operations?
To simplify boundary conditions during insertions and deletions.
30
True or False: In a BST, the depth of a node is the number of edges from the root to that node.
True
31
What is the primary operation performed to delete a node in a BST?
Rearranging the tree to maintain the BST properties after deletion.
32
What is the result of a pre-order traversal in a BST?
The root node is visited before its children.