Trees Flashcards

1
Q

A queue operates under a WHAT policy?

A

FIFO - First In, First Out

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

You may only read or remove the item at the WHAT of a queue?

A

Front/Head

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

You may only add an item at the WHAT of a queue?

A

Back/Tail

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

List the methods of Java’s Queue interface.

A

add(E item), element(), offer(E e), peek(), poll(), remove()

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

The element() method of Java’s Queue interface removes the head of the queue: true or false?

A

False; it retrieves, but does NOT remove the head of the queue.

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

You want to insert an item into a queue. Which one of Java’s Queue interface methods do you use?

A

Either add(E e) or offer(E e). The only difference is in the return type.

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

You want to retrieve, but NOT remove, the first element in a queue. Which one of Java’s Queue interface methods do you use?

A

Either E element() or E peek(). The only difference is in the return type.

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

You want to retrieve AND remove the first element in a queue. Which one of Java’s Queue interface methods do you use?

A

Either E remove() or E poll(). The only difference is in the return type.

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

A Deque allows insertion and deletion at both the head and tail: true or false?

A

True. That’s why it’s called a DOUBLY ENDED Queue.

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

Number of edges in a tree = ?

A

Number of vertices - 1.

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

Define “minimally connected”.

A

The tree will become disconnected if any edge is removed.

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

Define “maximally acyclic”.

A

If an edge is added, the tree will contain a cycle.

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

The child of a child of a given node is referred to as?

A

A “descendant”.

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

A node that has no children is called?

A

A “leaf”.

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

What is the height of a node?

A

The distance of a node from its deepest descendant.

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

A node has three children. What is the node’s degree?

A

Three. A node’s degree is defined as the number of children that node has. A leaf has a degree of 0.

17
Q

In a binary tree, each node has no more than how many children?

A

Two.

18
Q

Put these three in order for a preorder traversal: visit, traverse left, traverse right.

A

Visit, traverse left, traverse right.

19
Q

Put these three in order for a postorder traversal: visit, traverse left, traverse right.

A

Traverse left, traverse right, visit.

20
Q

Put these three in order for an inorder traversal: visit, traverse left, traverse right.

A

Traverse left, visit, traverse right.

21
Q

List the types of tree traversal.

A

Preorder, inorder, postorder, and level-order.

22
Q

If a tree is empty, what is its height?

A

-1

23
Q

If a tree is NOT empty, what is its height?

A

1 + max(height of left subtree, height of right subtree)

24
Q

What is the definition of a set?

A

A collection of elements with NO duplicates.

25
Q

What is the binary search tree property?

A

For any node X, every key
in the left subtree of X is less than X’s key, and every key in the right subtree of X is greater than X’s key.

26
Q

The binary search tree representation of a set is unique: true or false?

A

False. The BST representation of a set is NOT unique.

27
Q

A(n) ___ traversal of a binary search tree visits the nodes in sorted order.

A

Inorder.

28
Q

Balanced trees have a height of?

A

O(log n)