BST Pt. 1

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/26

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

27 Terms

1
New cards

What is a binary tree?

A data structure in which each node stores data and has up to two children.

2
New cards

What is a leaf in a binary tree?

A tree node with no children.

3
New cards

Define an internal node.

A node with at least one child.

4
New cards

What is the root of a binary tree?

The one tree node with no parent.

5
New cards

What is the depth of a node?

The number of edges on the path from the root to the node.

6
New cards

What is the height of a tree?

The largest depth of any node in the tree.

7
New cards

What defines a full binary tree?

Every node contains 0 or 2 children.

8
New cards

What is a complete binary tree?

All levels, except possibly the last, contain all possible nodes, and all nodes in the last level are as far left as possible.

9
New cards

Define a perfect binary tree.

All internal nodes have 2 children and all leaf nodes are at the same level.

10
New cards

What is a subtree?

Any node in the tree and all of its descendants.

11
New cards

What is a binary search tree (BST)?

A binary tree where each node's key is greater than all keys in the left subtree and less than all keys in the right subtree.

12
New cards

What is the search operation in a BST?

It returns the first node with a matching key or null if no match is found.

13
New cards

What is the runtime complexity of searching in a BST?

O(H), where H is the height of the tree.

14
New cards

What is the minimum height of a binary tree with N nodes?

log2(N).

15
New cards

What is the BSTNode class?

It represents a node in a binary search tree with fields for key, left child, and right child.

16
New cards

What does the BinarySearchTree class represent?

It represents a binary search tree with a reference to the root node.

17
New cards

What is the insert operation in a BST?

It inserts a new node in a proper location while obeying the BST ordering property.

18
New cards

What is the complexity of the insert-node operation?

Best case O(log2(N), worst case O(N).

19
New cards

What is a node's successor in a BST?

The node that comes after it in the BST ordering.

20
New cards

How do you find a node's successor if it has a right subtree?

It's the leftmost child of the right subtree.

21
New cards

What happens when removing a leaf node in a BST?

The parent's left or right child is assigned null.

22
New cards

What is the process for removing an internal node with two children?

Locate the successor, copy it to the node, and recursively remove the successor from the right subtree.

23
New cards

What is the purpose of the insertKey() method?

It checks if a key already exists and inserts a new node if it does not.

24
New cards

What is the runtime complexity of the insertKey() method?

Best case O(log2(N), worst case O(N)..

25
New cards

What defines a balanced BST?

The height difference between the left and right subtrees of every node is no more than 1.

26
New cards

What is the search runtime complexity in a balanced BST?

O(log N).

27
New cards

What is the significance of the BST structure for search operations?

It enables much faster search, insert, and remove operations compared to a linked list.