Unit 2: Trees Flashcards

1
Q

n-trees

A

trees with more than two children

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

n-tree application

A

the linux ls command

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

Binary tree

A

Tree in which each node has at most two children

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

Binary Search Tree

A

Binary tree in which all nodes are ordered from left to right

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

leaf

A

node with no children

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

height

A
  • length of longest path from root to leaf
  • start from bottom when determining height
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

depth

A

length from root to specific node

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

max number of nodes formula

A

2^(h+1) - 1

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

when is a tree full?

A

when its at its maximum capacity for its height

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

when is a tree complete?

A

when each node has either zero or two children and the leaves are ordered from left to right with no gaps

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

PostOrder traversal

A

Left, Right, Print

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

InOrder traversal

A

Left, Print, Right

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

Sequential Trees

A

efficiently storing a tree onto a disc

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

Less efficient way of representing a BT as a sequential tree

A

PreOrder traversal while representing null links with a /

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

More efficient way of representing a BT as a sequential tree

A

PreOrder traversal with internal nodes being represented with a prime mark, all null links being represented by a / however a leaf’s null links are not represented at all.
- A’ = internal Node
- B = leaf
- / = null link

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

n-tree representation on a sequential tree

A

convert tree to first child/next sibling implementation, conduct preOrder traversal with all leaf nodes being represented with a ) next to it, as well as ) indicating the end of a child list

17
Q

when is a tree balanced?

A

when the height of a nodes left and right children differ by no more than 1

18
Q

AVL Tree

A

a BST that remains balanced upon inserting and deleting nodes

19
Q

Rules for AVL Tree

A
  1. Find the lowest OOB node
  2. perform either a single or double rotation depending on the situation
20
Q

when to perform a single rotation

A

when the new item does NOT fall between the lowest OOB node and its descendant on the out of balance path

21
Q

single rotation

A

bring the OOB node’s child up

22
Q

when to perform a double rotation

A

when the new item FALLS between the lowest OOB node and its descendant on the OOB path

23
Q

double rotation

A

bring OOB node’s grandchild up, then relink any left or right children of the grandchild properly in the BST

24
Q

Binary Expression

A

tree in which operands make up the leaves and operators make up all other nodes.

25
Q

Splay tree

A

a BST that moves each node accessed to the root node

26
Q

What happens when your grandparent is a zig-zag or zag-zig away

A

perform a double rotation like AVL

27
Q

what happens when your grandparent is a zig-zig or zag-zag away

A

move you’re accessed node into the grandparent’s slot, attach the nodes traversed directly to the subtree of the accessed nodes. Make sure still BST

28
Q

What happens when you do not have a grandparent

A

simply move the accessed node up and keep the tree ordered

29
Q

Union

A

just like a struct but holds only one active value

30
Q

Why does a BET use a union?

A

so each node can hold either an operand or an operator at one time

31
Q

what is the runtime of a single zig-zag or zag-zig?

A

O log (n)

32
Q

what is the average runtime to splay a tree completely?

A

O ( M log n ) where M = average # of steps to amortize

33
Q

Binary Expression Tree

A

Postfix Notation expressed as a Expression Tree

34
Q

how to evaluate a postfix expression

A

push operands onto stack, when an operator is found, pop two operands from stack and solve second (operator) first, then push result back onto stack

35
Q

how to convert to postfix

A

write out numbers, push ( and operators onto stack. If an operator is already at the top of the stack, pop it and apply the new operator if it has equal or higher precedence of the current one. When a ) is seen, push onto stack then pop all operators until ( is popped. When end of input, pop all remaining stack symbols

36
Q

how to convert postfix to BET

A

turn stack on side and push pointers to operands onto stack, when an operator is found, pop last two pointers and make them children of operator, then push pointer to operator with children onto stack. FIRST OPERAND POPPED BECOMES RIGHT CHILD AND SECOND BECOMES LEFT CHILD

37
Q

least number of leaves

A

1

38
Q

most number of leaves

A

n/2