Tree Nodes Flashcards

1
Q

A leaf node is a node…

A

that has no children

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

True or False.
Any node with a child is an internal node

A

True

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

How many children can a node have in a binary tree?

A

It can have up to 2 children

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

What is the depth of a root node?

A

0

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

If a tree has just one node what is the depth?

A

0

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

A link from a node to a child is called a…

A

edge

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

A binary tree is full if…

A

Every node contains 0 or 2 children

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

A binary tree is perfect if…

A

All internal nodes have 2 children and all leaf nodes are at the same level

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

A binary tree is complete if…

A

All levels, except the last level, contain all possible nodes and all nodes in the last level are as far left possible

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

What is a binary search tree?

A

Orders the left child of the less than or equal to the parent node
Orders the right child greater than or equal to the parent node

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

Where does searching begin in a tree?

A

It begins at the root

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

Example: If you are searching for 145 in a tree and the root of the node is 300, where will the search begin?

A

145< 300, so the search will begin with the left child

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

If a match is not found what is returned?

A

Null

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

Insert as a node as a left child involves…

A

If the new node is less than the current node
The current nodes left child is null

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

Insert a node as a right child involves…

A

If the new node’s key is greater than or equal to the current node
The current node right child is null

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

Searching for an insert location involves…

A

If the right or left child is not null
The algorithm assigns the current node with that child and continues looking for a proper location

17
Q

What is a tree traversal?

A

Visits all the nodes in the tree and performs an operation on each node

18
Q

What is an inorder traversal?

A

Visits all the nodes in a BST from smallest to largest

19
Q

What is the algorithm for in order traversal?

A

left current right

20
Q

What is the height of a tree?

A

Is the maximum number of edges from the root of the tree

21
Q

If a tree’s height is N=7, what is the height?

A

h - 1 = 7 - 1 = 6
Therefore the answer is 6.

22
Q

How can you implement a search using recursion?

A

A base case is checking if the node is not null
If the key is equal to the node
If the key is less than
node–> key return

23
Q

What is a preorder traversal?

A

Starts at the root node than works its way down the left side of child then the right side
Moves on to the right side of the tree and goes through the left children than the right children

24
Q

What is inorder traversal?

A

Starts on the left subtree than the root node then moves on to the right subtree

25
Q

What is post order traversal?

A

Starts on the left subtree than the right sub tree and then the root node

26
Q

What does the find(key) method do?

A

Returns the reference to node containing key if present

27
Q

What does the findMin() do?

A

Returns the node containing the smallest key

28
Q

What does the findMax() do?

A

Returns the node containing the largest key

29
Q

What does add(key) do?

A

Inserts a new node in tree at correct position(unless already present)

30
Q

What does remove(key) do?

A

Removes key from tree if present