Comprehensive Guide to Trees and Binary Search Trees in Data Structures

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/52

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 12:16 AM on 5/6/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

53 Terms

1
New cards

What is a general tree?

A general tree T is a set of one or more nodes partitioned into a root node and disjoint subsets that are general subtrees of the root.

2
New cards

What defines a binary tree?

A binary tree is a set T of nodes that is either empty or partitioned into a root node and two possibly empty binary subtrees.

3
New cards

What are the properties of a binary search tree?

In a binary search tree, a node's value is greater than all values in its left subtree and less than all values in its right subtree.

4
New cards

How is the height of a tree defined?

The height of a tree T is the maximum level of its nodes, with an empty tree having a height of 0.

5
New cards

What is a full binary tree?

A full binary tree is one where every node has either 0 or 2 children.

6
New cards

What is a complete binary tree?

A complete binary tree of height h is full to level h-1 and filled from left to right at level h.

7
New cards

What characterizes a balanced binary tree?

A balanced binary tree is one where the height of any node's left and right subtrees differs by no more than 1.

8
New cards

What is the root of a tree?

The root is the only node in the tree that has no parent.

9
New cards

Define a leaf node.

A leaf node is a node that has no children.

10
New cards

What are siblings in a tree?

Siblings are nodes that share the same parent.

11
New cards

What is the ancestor of a node?

An ancestor of node n is any node on the path from the root to n.

12
New cards

What is a descendant of a node?

A descendant of node n is any node on a path from n to a leaf.

13
New cards

What is a subtree of a node?

A subtree of node n consists of a child of n and that child's descendants.

14
New cards

How is the height of a tree calculated?

The height is calculated as the number of nodes on the longest path from the root to a leaf.

15
New cards

What is an empty binary tree?

An empty binary tree is a binary tree that contains no nodes.

16
New cards

What operations are available for an ADT binary tree?

Basic operations include createBinaryTree(), makeEmpty(), isEmpty(), and getRootItem().

17
New cards

What is preorder traversal?

Preorder traversal visits the root node first, then recursively visits the left subtree followed by the right subtree.

<p>Preorder traversal visits the root node first, then recursively visits the left subtree followed by the right subtree.</p>
18
New cards

What is inorder traversal?

Inorder traversal visits the left subtree first, then the root node, and finally the right subtree.

19
New cards

What is postorder traversal?

Postorder traversal visits the left subtree first, then the right subtree, and finally the root node.

20
New cards

What is an array-based representation of a binary tree?

An array-based representation uses an array to store tree nodes, where each node contains data and indexes for its children.

<p>An array-based representation uses an array to store tree nodes, where each node contains data and indexes for its children.</p>
21
New cards

What is a reference-based representation of a binary tree?

A reference-based representation uses references to link nodes in the tree.

<p>A reference-based representation uses references to link nodes in the tree.</p>
22
New cards

What is the role of the TreeNode class in a binary tree?

The TreeNode class represents a node in a binary tree.

23
New cards

What is the purpose of the TreeException class?

The TreeException class is used to handle exceptions related to tree operations.

24
New cards

What does the BinaryTree class provide?

The BinaryTree class provides general operations for a binary tree and extends the BinaryTreeBasis class.

25
New cards

What is the significance of the maximum level in a tree?

The maximum level indicates the height of the tree, which is crucial for understanding tree structure and balance.

26
New cards

How do you determine if a binary tree is balanced?

A binary tree is balanced if the heights of the left and right subtrees of any node differ by at most 1.

27
New cards

What does the TreeIterator implement?

The Java Iterator interface.

28
New cards

What is the purpose of the TreeIterator?

To provide methods to set the iterator to the type of traversal desired.

29
New cards

What data structure does the TreeIterator use to maintain the current traversal?

A queue.

30
New cards

What is a key property of a binary search tree?

Each node's value is greater than all values in its left subtree and less than all values in its right subtree.

31
New cards

What is a record in the context of binary search trees?

A group of related items, called fields, that are not necessarily of the same data type.

32
New cards

What is a search key?

The part of a record that identifies it within a collection of records.

33
New cards

What operations can be performed on a binary search tree?

Insert, delete, retrieve, and traverse items.

34
New cards

What does the search algorithm do in a binary search tree?

It searches the binary search tree for the item whose search key is specified.

35
New cards

What are the three possible cases for a node containing an item to be deleted?

1. N is a leaf. 2. N has only one child. 3. N has two children.

36
New cards

What happens if a node N is a leaf during deletion?

Set the reference in N's parent to null.

37
New cards

What is the strategy for deleting a node N with two children?

Locate another node M that is easier to remove, copy M's item to N, and remove node M.

38
New cards

How is the retrieval operation implemented in a binary search tree?

By refining the search algorithm to return the item with the desired search key or a null reference.

39
New cards

What is the theorem regarding inorder traversal of a binary search tree?

It visits the nodes in sorted search-key order.

40
New cards

What does the BinarySearchTree class extend?

It extends BinaryTreeBasis.

41
New cards

What is the maximum number of comparisons for retrieval, insertion, or deletion in a binary search tree?

The height of the tree.

42
New cards

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

⌈log2(n + 1)⌉.

43
New cards

What is Treesort?

An algorithm that uses the ADT binary search tree to sort an array of records into search-key order.

44
New cards

What is the average case efficiency of Treesort?

O(n * log n).

45
New cards

What is the worst-case efficiency of Treesort?

O(n²).

46
New cards

What traversal method is used to save a binary search tree to a file?

Preorder traversal.

47
New cards

What is required to restore a binary tree to a balanced shape?

The data must be sorted, and the number of nodes in the tree must be known.

48
New cards

What are the two binary search methods in JCF?

1. Based on natural ordering. 2. Based on a specified Comparator.

49
New cards

What is the significance of the shape of a binary search tree?

It determines the efficiency of its operations.

50
New cards

How can a binary search tree be restored to its original form?

By performing preorder traversal while saving the tree to a file.

51
New cards

What is the maximum height of a binary search tree with n nodes?

n.

52
New cards

What does the term 'full binary tree' refer to?

A binary tree where every node other than the leaves has two children.

53
New cards

What is the relationship between the height of a binary search tree and the order of operations performed?

The height depends on the order of insertion and deletion operations.