Binary Search Tree Flashcards

1
Q

In what order is the node retrieved using Pre-order Traversal?

A

Root-Left-Right

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

In what order is the node retrieved using In-order Traversal?

A

Left-Root-Right

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

In what order is the node retrieved using Post-order Traversal?

A

Left-Right-Root

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

What are the key steps for searching in a BST?

A
  1. Beginning from the root node, compare the target key to the current node key. If less follow the left child, if more follow the right child.
  2. Repeat the process until target node is found where the current node key matches the target key.
  3. If the traversal ends without finding a match (reaching leaf node), the target key does not exist.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the key steps in adding a node to a BST?

A
  1. Beginning from the root node, compare the target key to the current node key. If less follow the left child, if more follow the right child.
  2. Repeat the process until it reaches a leaf node, the new key will be added at the missing edge.
  3. If a matching key is found, the new key is not added to prevent duplicates.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the minimum possible height of a BST for n number of nodes?

A

square root(n+1)

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

What is a binary tree?

A

A binary tree is a tree where each node has at most two children.

The two children of a node are commonly referred to as the left child and the right child of the node

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

What is a binary search tree?

A

A binary search tree is a binary tree in which all values smaller than a node are stored in that node’s left subtree and all values larger than a node are stored in that node’s right subtree

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

How can an unbalanced binary tree be rebalanced?

A

The binary search tree needs to be re-created or rebalanced with the same items to make it balanced

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

What are the advantages of Binary Search Tree? (3 in total)

A

Enables the use of binary search on a data structure that is guaranteed to remain sorted.

Adding elements into a BST has a time complexity of O(log n), vs append-and-sort operations for an array which have a time complexity of O(n log n) using merge sort.

Insertion and deletion of items involves the updating of pointers instead of rearranging elements, making the operations much more efficient, especially when the data stored in each entry is large

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

What are the disadvantages of Binary Search Tree?

A
  • Nodes of BST cannot be accessed by index
  • BST may become unbalanced in the course of usage, making binary search of the tree inefficient because the time complexity of binary search becomes almost O(n) instead of O(lg n) requires balancing to maintain optimal performance
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is an unbalanced binary search tree?

A

A binary search tree is unbalanced when one side of the tree has many more elements/nodes than the other side

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

Why is an unbalanced binary tree disadvantageous?

A

This makes binary search of the binary search tree inefficient
because the time complexity of binary search becomes almost O(n) instead of O(lg n)

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