Properties Of Trees Flashcards

1
Q

Each tree must have what?

A

Each tree must have a root node.

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

Trees cannot be what?

A

Trees cannot be cyclical.

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

Do nodes have to be in any particular order for you to have a tree?

A

No. Nodes may or may not be in any particular order.

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

What could the value of a node be?

A

A nodes value could be any data type.

ex: string, int, boolean

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

Can a nodes value link back to their parent?

A

Yes but it doesn’t have to.

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

What would a simple node class contain for a tree?

A
class Node
  :name, :children 
  # name could be value 
  # children an array 
End
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What would a simple tree class contain?

A

class Tree
:root
# has a root node and root can have children nodes
End

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

What determines if a tree is a binary tree?

A
  • each node must less then or equal to two children nodes.

- if this is not the case you may have an n-ary tree n being the amount of children nodes for example 10-ary

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

What are the properties of a leaf?

A

If node.children? == nil
node.leaf? = true.
End

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

What type of tree is a binary search tree?

A

A binary search tree is a type of binary tree.

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

What is unique about a binary search tree that makes it different then just a binary tree?

A

A binary search tree must fit the following ordering properties:

  • Left Descendants <= Current Node < Right D.
  • Sometimes not permitted to have duplicate values.
  • Sometimes duplicates; but will be on the right; or possibly either side.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

A binary search tree imposes what condition?

A

Nodes.each do |node|
If node.left <= node.current_node && node.current_node < node.right_node

Left descendants <= Current node < right d

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

What does a balanced tree not mean?

A

A balanced does not mean that the left and right sub-trees are of equal size. (This is a perfect tree).

*For problems with trees be sure to ask interviewer if it is balanced or not.

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

What should a “balanced” tree be thought of as?

A

You could think of a “balanced tree” as a “Not terribly unbalanced tree”.
- It must be balanced enough to meet O(log n) times for insert and find.

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

What are two types of balanced trees?

A
  • Red-Black-Tree

- AVL Tree

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

What do you call a Binary Tree in which every level of the tree is fully filled and is filled from left to right?

A

A Complete Tree

17
Q

What do you call a tree in which every node has <= 2 children.

A

Full Binary Tree

18
Q

What type of tree is both considered a Full Binary Tree and a Complete Binary Tree?

A

A Perfect Binary Tree is both full and complete!

19
Q

How could you determine if a binary tree is perfect if you have k number of levels and the number of nodes?

A

A binary tree must have 2^k-1 nodes for it to be a perfect binary tree. (K being the number of levels or degrees deep the tree is).

20
Q

What are the 3 types of Binary tree traversals?

A
  1. ) In-Order
  2. ) Pre-Order
  3. ) Post-Order
21
Q

What is the most commonly used binary tree traversal?

A

In-Order

22
Q

When used on a Binary Search Tree In-Order traversal visits nodes in ascending or descending order?

A

When performed on a binary search tree an In-Order traversal will visit nodes in Ascending order.

23
Q

In Pre-Order traversal what order are the nodes visited?

A

First the current node then the left node and then the right node. (NLR).

24
Q

For post-order traversal what order are the nodes visited in?

A

First the current node then the children. (NLR)

25
Q

For in-order traversal, what order are the nodes traversed?

A

In-Order first visits the left node then the current node and then the right node.