Binary Tree Flashcards

1
Q

what is a binary tree

A

nodes with links to left and right nodes

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

how to get the height of a tree with N nodes

A

lg N

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

what is binary heap

A

array representation of a heap ordered complete binary tree

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

nodes in a binary tree must always first be added from which direction

A

left

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

what is the rule about parents and children for binary trees

A

parent’s keys must not be smaller than their children’s keys

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

when a binary tree is put into a binary representation, what number do the indices start at

A

1

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

where is the largest key found in the binary tree array representation

A

a[1]

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

what is the first node (largest node) called in a binary tree

A

root

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

where is the parent of node k found in array representation of binary tree

A

k/2

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

where are the children of node k found in array representation of binary tree

A

2k (left)

2k+1 (right)

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

the left subtree of k is empty if

A

2k > N

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

the right subtree of k is empty if

A

2k+1 > N

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

when is k a leaf node

A

2k > n

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

what is a leaf node

A

a node without isblings

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

is a binary tree completely sorted

A

no

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

when inserting into a binary tree, where is node first added

A

add to the end

17
Q

how does insert work in binary trees

A

add node to the end

swim node up to the top by exchanging children with parent if it is larger than the parent

18
Q

how does remove work in binary trees

A

remove root by exchanging with the node at the end, sink this node down

19
Q

what would the most number of comparisons be in the insertion method

A

logN

worst case would be it swims up to the root, so =height of the tree

20
Q

what would the maximum number of insertions be in a delete functions

A

logN

worst case is it sinks all the way down
cost = logN = height of tree

21
Q

ways to improve the binary tree

A

half swaps

d-way trees

22
Q

what are half swaps

A

instead of swapping each time, swim one value up until it finds it position then sink all the other values down by 1

23
Q

what is the height of a d-way binary tree

A

log vd N

24
Q

where is the sweet spot of d way trees

A

4

constant time improvement

25
Q

any more than d=4 is inefficient, why

A

comparisons dominate run time

26
Q

is binary heap cache friendly, hwy

A

no

elements aren’t accessed in a linear order
(ie keys are accessed that aren’t in cache as arrays are divided up into blocks, keys could be accessed that are outside of the current block)

27
Q

cost of delete in d way tree

A

d log vd N

28
Q

two nodes that have the same parent are called what

A

siblings