Questions Chapter 8 Flashcards

1
Q

Trees consist of ______ connected by ______.

A

Trees consist of nodes connected by edges.

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

In a binary tree, a node has at most ____ children.

A

two

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

In a binary tree, all the nodes that are _____ descendants of Node A have key values _____ than A; all the nodes that are A’s _____ descendants have key values ______ than or equal to A.

A

left descendants have key values less than A, right descendants have key values greater than or equal to A.

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

Trees perform searches, insertions, and deletions in ______ time.

A

O(log N) time

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

An unbalanced tree is one whose root has many more ______ descendants than _____ descendants or vice-versa.

A

left than right, right than left descendants

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

Insertion involves finding the place to insert the new node and then changing a _______ field in its new _______ to refer to it.

A

change a child field in its new parent to refer to it

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

An ________ traversal visits nodes in order of ascending keys.

A

inorder traversal

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

When a node has ____ child/children, it can be deleted by setting the _____ field in its parent to null.

A

zero children, set child field in parent to null.

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

When a node has _____ child/children, it can be deleted by setting the _______ field in its parent to point to its _______.

A

one child, set child field in parent to its child.

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

When a node has ______ child/children, it can be deleted by replacing it with its successor.

A

two children

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

The successor to node A can be found by finding the ________ node in the subtree whose ______ is A’s _____ child.

A

find the minimum node in the subtree whose root is A’s right child.

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

Insertion and deletion in a tree require what big O time?

A

O(logN)

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

A binary tree is a search tree if:

a. every non-leaf node has children whose key values are less than (or equal to) the parent.
b. every left child has a key less than the parent and every right child has a key greater than (or equal to) the parent
c. in the path from the root to every leaf node, the key of each node is greater than (or equal to ) the key of its parent
d. a node can have a maximum of two children

A

b. every left child has a key less than the parent and every right child has a key greater than (or equal to) the parent.

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

True or False: Not all trees are binary trees.

A

True

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

In a complete binary tree with 20 nodes, and the root considered to be at level 0, how many nodes are there at level 4?

A

5

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

A subtree of a binary tree always has:

a. a root that is a child of the main tree’s root
b. a root unconnected to the main tree’s root
c. fewer nodes than the main tree
d. a sibling with the same numer of nodes

A

c. fewer nodes than the main tree.

17
Q

In the Java code for a tree, the ______ and the _______ are generally separate classes.

A

the node and the tree are separate classes.

18
Q

Finding a node in a binary search tree involves going from node to node, asking:

a. how big the node’s key is in relation to the search key
b. how big the node’s key is compared to its right or left children
c. what leaf node we want to reach
d. what level we are on

A

a. how big the node’s key is in relation to the search key

19
Q

An unbalanced tree is one:

a. in which most of the keys have values greater than the average
b. whose behaviour is unpredictable
c. in which the root or some other node has many more left children than right children, or vice versa.
d. that is shaped like an umbrella

A

c.

20
Q

Inserting a node starts with the same steps as ________ a node.

A

finding a node

21
Q

Suppose node A has a successor node S. Then S must have a key that is larger than _________, but smaller than or equal to ___________________.

A

S key larger than A, but smaller than or equal to A’s left child descendants

22
Q

In a binary tree used to represent a mathematical expression, which of the following is NOT true:

a. both children of an operator node must be operands
b. following a postorder traversal, no parenthesis need to be added
c. following an inorder traversal, parentheses must be added
d. in pre-order traversal, a node is visited before either of its children

A

d. in pre-order traversal, a node is visited before either of its children

23
Q

If a tree is represented by an array, the right child fo a node at index n has an index of _________.

A

2*index+2

24
Q

True or False: Deleting a node with one child from a binary search tree involves finding that node’s successor.

A

False