Binary Tree Flashcards

1
Q

Mathematical Definition of a Binary Tree

A

A structure composed of zero or more nodes, each node having a label of some mathematical type (say T) called the label type

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

Structure of a Binary Tree

A

A binary tree is either an empty tree (zero nodes), or a non-empty tree which consists of a root node of type T and two sub-trees, each of which is a binary tree itself. Since a non-empty binary tree is made up of binary trees, it has a recursive structure.

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

Which methods does BinaryTree interface have contracts defined for?

A

T root(), T replaceRoot(T x), int height(), and void inOrderAssemble(T root, BinaryTree<T> left, BinaryTree<T> right)*
(* - inOrderAssemble not important)</T></T>

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

Which interface does BinaryTree extend?

A

BinaryTreeKernel

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

Which methods does BinaryTreeKernel interface have contracts defined for?

A

void assemble(T root, BinaryTree<T> left,
BinaryTree<T> right), T disassemble(BinaryTree<T> left,
BinaryTree<T> right), int size()</T></T></T></T>

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

Size of a BinaryTree? How is size of a BinaryTree ‘t’ denoted in Java documentation?

A

The total number of nodes in the tree; |t|

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

Height of a BinaryTree? How is height of a BinaryTree ‘t’ denoted in Java documentation?

A

The total number of nodes on the longest path from the root to an empty sub-tree of a BinaryTree; ht(t)

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

Labels of a BinaryTree? How are lables of a BinaryTree ‘t’ denoted in Java documentation?

A

The set whose elements are exactly the labels of t (since it’s a set, no duplicates and no order necessary); labels(t)

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

Suppose you have a BinaryTree of type Integer which has 4 as its root, 2 as the root of the left sub-tree and 3 as the root of the right sub-tree. What is the mathematical value of this BinaryTree?

A

compose (4, compose(2, empty_tree, empty_tree), compose(3, empty_tree, empty_tree))

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

Which class(-es) implements the BinaryTree interface?

A

BinaryTree1

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

What does the no-argument BinaryTree constructor create?

A

It ensures this = empty_tree

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

How would you create a BinaryTree of String type called t using the no-argument constructor?

A

BinaryTree<String> t = new BinaryTree1<>();</String>

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