SW10: Trees Flashcards

(84 cards)

1
Q

An in-order traversal of the expression tree for (a - b) * c would result in which sequence?

A

a - b * c

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

A collection of disconnected trees is called a:

A

Forest

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

The degree of a tree is defined by:

A

The maximum degree of any vertex in the tree.

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

A tournament bracket… is a perfect real-world example of what kind of tree?

A

A full binary tree

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

Which tree theorem is most critical for understanding the maximum performance of database search operations?

A

The theorem relating the height to the number of nodes (h is at least lg(n+1) - 1).

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

The Java constructor public BTNode(T el) calls this(el, null, null);. What is the purpose of this line?

A

To call the other constructor, reusing its logic to set children to null.

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

Which of the following is the biggest drawback of using K-ary Tree Representation 1 (“One pointer per potential child”)?

A

Poor space efficiency for non-uniform trees.

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

In the breadthFirst algorithm, what is the purpose of the line p = dequeue()?

A

To get the next node to visit from the front of the queue.

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

An Abstract Data Type (ADT) is composed of:

A

Data and Operations

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

What does the getParent(n) operation return?

A

The direct parent node of n.

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

What is a “subtree”?

A

Any node in a tree and all of its descendants.

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

The term “ordered binary tree” implies that:

A

The positions of the left and right children are distinct and meaningful.

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

If you call setRight(n, el) on a node n that already has a right child, what is the outcome?

A

The existing right child and its entire subtree are replaced by the new node.

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

Fill in the Blank: The toString(T) operation typically starts by calling toString(n) on the root.

A

root

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

Fill in the Blank: The time complexity of a Breadth-First traversal is O(n).

A

O(n)

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

Fill in the Blank: The base case for the recursive depth-first traversals checks if the current node is null.

A

null

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

In an array representation of an almost complete binary tree, the parent of a node at index k is at index: (for 1-based indexing).

A

l k/2 l

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

The breadthFirst algorithm is:

A

iterative.

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

The acronym for Inorder traversal is:

A

LVR

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

To create a syntax tree, the algorithm first converts the infix expression to:

A

postfix

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

Two nodes that have the same parent are called:

A

siblings

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

A subtree consists of a node and all of its:

A

descendants

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

The operation isEmpty(T) returns true if T.root is:

A

null

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

The “first-child, next-sibling” representation is an example of a:

A

linked list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
The number of children a specific node has is its:
degree
26
The new(btnode, el) constructor is ideal for creating a new:
leaf node
27
Overwriting a child pointer using setLeft or setRight will disconnect the old subtree from the tree.
disconnect
28
A Preorder traversal is also known as a:
depth-first traversal
29
The ExprToSyntaxTree algorithm uses a stack of tree nodes to build the tree.
stack
30
In K-ary Tree Representation 2, parent retrieval time is:
O(1)
31
The number of vertices at level L of a complete binary tree is:
2^L
32
What is the defining characteristic of a Depth-First Traversal (DFT)? A. It processes all nodes at one level before moving to the next. B. It uses a queue data structure to manage visited nodes. C. It explores as far down one path as possible before backtracking. D. It always selects the node with the highest priority to visit next.
C. It explores as far down one path as possible before backtracking.
33
In the ExprToSyntaxTree algorithm, what is the purpose of the stack? A. To store the final, constructed syntax tree. B. To hold the operands and operators of the expression. C. To temporarily store variables and their values. D. To hold temporary tree nodes during the tree's construction.
D. To hold temporary tree nodes during the tree's construction.
34
In K-ary Tree Representation 2 ("Pointer to parent"), how would you find the siblings of a given node n? A. Check the pointers of all other nodes to see which ones point to n. B. Follow the parent pointer of n, then search the entire tree for other nodes that point to n's children. C. Search the entire tree for all nodes at the same height as n. D. Follow the parent pointer of n, then search the entire tree for other nodes that point to that same parent.
D. Follow the parent pointer of n, then search the entire tree for other nodes that point to that same parent.
35
What is the height of a single-node tree? A. 1 B. log₂(1) C. 0 D. Undefined
C. 0
36
Which of the following is NOT a property of a tree? A. There is a unique path between any two vertices. B. A tree with n vertices has exactly n−1 edges. C. It is a connected acyclic graph. D. Every node can have multiple parents.
D. Every node can have multiple parents.
37
In the Java BTNode class, what is the purpose of the generic type? A. To restrict the node data to only primitive types like int or double. B. To signify that the node is a Binary Search Tree node. C. To enforce that the data held must be comparable. D. A generic type parameter, allowing the node to hold any type of data.
D. A generic type parameter, allowing the node to hold any type of data.
38
In the BTNode class, the isLeaf(n) operation is given a BTNode n. Why would it return false if n is null? A. Because null is considered a branch, not a leaf. B. To indicate that the tree is empty. C. To throw a NullPointerException and halt the program for debugging. D. To prevent a NullPointerException when checking n.left and n.right.
D. To prevent a NullPointerException when checking n.left and n.right.
39
Fill in the Blank: The topmost node in a tree is called the root.
root
40
Fill in the Blank: The level or depth of the root vertex is always zero.
zero
41
Fill in the Blank: A binary tree where all interior nodes have two children and all leaves are at the same level is a full binary tree.
full
42
Fill in the Blank: According to the tree theorems, a full binary tree with k internal vertices has k + 1 leaves.
k + 1
43
Fill in the Blank: The new(btree) operation initializes the root pointer to null.
null
44
Fill in the Blank: The info part of a btnode record holds the actual data of the node.
data
45
Fill in the Blank: In K-ary Tree Representation 1, child retrieval time is O(1).
O(1)
46
True or False: A tree is a linear data structure.
False
47
True or False: A rooted tree must have exactly one node with no parent.
True
48
True or False: In a tree, the path between any two vertices is always unique.
True
49
True or False: A node's ancestors include its siblings.
False
50
True or False: A binary tree can have a node with three children.
False
51
True or False: The height of a tree is defined by the level of its root node.
False
52
True or False: A full binary tree can have nodes with only one child.
False
53
True or False: A complete binary tree can have gaps on its last level, as long as they are on the right side.
False
54
True or False: A tree with 10 vertices will have exactly 9 edges.
True
55
True or False: The isLeaf(n) operation would return true for an internal node.
False
56
True or False: In the Java BTNode implementation, the BTNode(T el)constructor is primarily used for creating internal nodes.
False
57
True or False: The setRoot(T, n) operation creates a new node from raw data and sets it as the root.
False
58
True or False: K-ary Tree Representation 1 ("One pointer per potential child") is highly space-efficient for non-uniform trees.
False
59
True or False: In K-ary Tree Representation 2 ("Pointer to parent"), finding a node's parent is an O(1) operation.
True
60
Which property of trees guarantees that such a path is the only one?
The simple path between any two vertices is unique.
61
According to the tree theorems, what should be your primary goal for the tree's structure for search performance?
Keep the height of the tree as low as possible.
62
Which traversal strategy is most naturally suited for showing hierarchy (processing a parent before its children)?
Preorder
63
You need to store a k-ary tree where the most common operation is finding an employee's direct manager. Which representation is the best fit?
Pointer to parent (Representation 2)
64
In the "first-child, next-sibling" representation, how are all the direct children of a single node linked together?
Through a singly linked list using the "next sibling" pointers.
65
In an array representation of an almost complete binary tree (1-based indexing), a node is at index k=5. Where is its left child located?
Index 10
66
The isLeaf(n) operation returns true if and only if:
n.left is null AND n.right is null.
67
What is the primary functional difference between setRoot(T, el) and setRoot(T, n)?
setRoot(T, el) creates a new node, while setRoot(T, n) uses an existing node.
68
A system that manages a print queue would process jobs in an order analogous to which traversal?
Breadth-First
69
What is the state of the queue in the Breadth First algorithm just before the while loop begins?
It contains only the root node.
70
The recursive calls in the depth-first traversal algorithms stop when what condition is met?
The root of the subtree being traversed is null.
71
To build a syntax tree from a postfix expression A B + C *, what is the last operation performed by the ExprToSyntaxTree?
A new tree with * as the root is pushed onto the stack.
72
True or False: The "first-child, next-sibling" representation uses three pointers per node.
False
73
True or False: An almost complete binary tree is poorly suited for an array representation due to wasted space.
False
74
True or False: The isEmpty(T) operation checks if the number of nodes is zero by looking at the T.root pointer.
True
75
True or False: Calling setLeft(n, el) on a node n that already has a left child will result in an error.
False
76
True or False: Breadth-First Traversal explores one branch of a tree as deeply as possible before backtracking.
False
77
True or False: A queue is the essential data structure for implementing a recursive Preorder traversal.
False
78
True or False: The visit action in a Postorder traversal happens before traversing the left and right subtrees.
False
79
True or False: The time complexity for all three main depth-first traversals is O(n).
True
80
True or False: The ExprToSyntaxTree algorithm works directly on the infix expression to build the tree.
False
81
True or False: A Preorder traversal of a syntax tree yields the postfix expression.
False
82
True or False: Grandchildren are considered direct children in a tree.
False
83
An information system needs to model a company's organizational chart. Which term best describes the entire chart?
A rooted tree
84
In a file system, the C:\ drive has a folder named Users, which contains a folder named Documents. What is the relationship of Documents to C:?
Documents is a descendant of C:.