(Ch. 20) Understanding Binary Trees and Their Operations

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/41

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.

42 Terms

1
New cards

binary tree

A nonlinear linked structure where each node may point to up to two child nodes.

2
New cards

root node

The first node in a binary tree, serving as the entry point.

3
New cards

child node

A node that descends from another node in a binary tree.

4
New cards

leaf node

A node with no children.

5
New cards

subtree

A branch of the tree starting from any node and including all its descendants.

6
New cards

binary search trees rule

The left child holds a lesser value; the right child holds a greater value.

7
New cards

IntBinaryTree class

To store and manipulate integers in a binary search tree structure.

8
New cards

TreeNode struct

struct TreeNode { int value; TreeNode left, right; };

9
New cards

insertNode function

Creates and inserts a new node into the binary search tree.

10
New cards

inorder traversal

Left subtree → Current node → Right subtree.

11
New cards

preorder traversal

Current node → Left subtree → Right subtree.

12
New cards

postorder traversal

Left subtree → Right subtree → Current node.

13
New cards

searchNode(int)

Returns true if a value exists in the tree; otherwise false.

14
New cards

remove(int)

Removes a node with the specified value from the tree.

15
New cards

node with two children deletion

Right subtree is linked to parent; left subtree is attached to the leftmost node of the right subtree. delete the replacement node

16
New cards

makeDeletion()

Reattaches subtrees and deletes the node.

17
New cards

tree template

Generic binary search trees that can store any data type.

18
New cards

binary tree template operators

Operators <, >, and == must be supported.

19
New cards

insertion order effect

It determines the structure and balance of the tree.

20
New cards

destroySubTree() purpose

Deletes all nodes in the tree recursively, used in the destructor.

21
New cards

remove() function internal call

Internally calls deleteNode() to locate and remove the node.

22
New cards

binary tree ascending order print

By using inorder traversal.

23
New cards

What tree results from inserting 10, 5, 15, 2 into a BST?

10 root, 5 left, 15 right, 2 under 5.

24
New cards

What does insert(TreeNode *&node, int val) do?

Inserts into BST by modifying node by reference.

25
New cards

What is base case in any traversal?

if (node == nullptr) return;

26
New cards

What is preorder traversal of 10, 5, 15?

10 5 15

27
New cards

How do you count all nodes?

return 1 + count(left) + count(right)

28
New cards

What does makeDeletion() do?

Handles replacement and cleanup of a node in deletion.

29
New cards

Why use template with BinaryTree?

To store any comparable type (supports <, >, ==).

30
New cards

What happens if T doesn't support < in BinaryTree?

Compilation fails — missing operator.

31
New cards

Why use TreeNode*& in insert/delete?

Allows modifying actual pointer passed from parent.

32
New cards

What must destructor of BinaryTree do?

Recursively delete all nodes (postorder).

33
New cards
Q: What happens when you delete a leaf node from a binary tree?
A: Simply remove the node and set its parent's pointer to nullptr.
34
New cards
Q: What happens when you delete a node with one child?
A: Replace the node with its only child by linking the parent to the child.
35
New cards

Q: What is the inorder successor in a binary search tree?

A: The smallest value node in the right subtree of the node being deleted - the next node in inorder traversal.

36
New cards
Q: What is the replacement called when using the largest node in the left subtree?
A: Inorder predecessor.
37
New cards
Q: What is the inorder predecessor in a binary search tree?
A: The largest value in the left subtree — the previous node in inorder traversal.
38
New cards
Q: What is outdegree in a directed graph?
A: The number of edges leaving a node.
39
New cards
Q: What is indegree in a directed graph?
A: The number of edges coming into a node.
40
New cards
Q: How can you find outdegree from an adjacency list?
A: Count how many nodes are listed in that vertex’s list.
41
New cards
Q: How can you find indegree from an adjacency list?
A: Count how many times the vertex appears in all lists.
42
New cards

Q: What happens when you delete a node with two children?

A: Replace it with its inorder successor (smallest value in right subtree), then delete that successor.