Binary Trees Flashcards

1
Q

give the Tree ADT

A

e = element, v = node

root()
insert(e)
remove(v)
find(e)
parent(v)
children(v)
elements()
isExternal(v)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

describe the binary Tree ADT

A
at most two children. children replaced with left and right
adds sibling(v)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what is depth and what is height

A

depth, number of ancestors excluding self

height, maximal depth

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

what is a proper/full binary tree

A

either 0 or 2 children

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

what is a complete tree

A

all levels full, except for last, where all nodes are as far left as possible

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

what is a perfect tree

A

proper tree where all external nodes have equal depth

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

what is an ordered tree

A

all elements left < right and stored element, and stored element < right

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

what is a sparse tree

A

lots of empty elements

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

how would a binary tree be represented using vector (array) represenation

A

A[0] = root
parent = A[(k-1)/2]
left child = A[2k+1]
right child = A[2k+2]

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

how would a binary tree be represented in a linked structure

A

each node has: value, left pointer, right pointer

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

what is a traversal

A

systematic way of visiting each node

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

describe pre-order traversal

A

node then children

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

describe post-order traversal

A

children then node

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

describe in-order traversal

A

left then node then right

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

describe depth first search

A

search children before sibling

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

describe breadth first search

A

search cell nodes at same level before incrementing level

17
Q

what is a binary search tree

A

ordered binary tree

18
Q

describe balance

A

achieved y rotations

assures us about height

19
Q

describe when a single left rotation (LL) is performed and how

A

A becomes unbalanced when a node is inserted in the right subtree of A’s right subtree (B). We perform the left rotation by making A the left-subtree of B. A takes ownership of B’s left child as its right child
B takes ownership of A as its left child

20
Q

describe when a single right rotation (RR) is performed and how

A

the unbalanced node is inserted in the left subtree of C’s left subtree (B).

B becomes the new root.
C takes ownership of b’s right child, as its left child.
B takes ownership of C, as it’s right child

21
Q

describe a double left rotation

A

otherwise known as: left right

perform a right rotation on the right subtree
then left rotation on the root

22
Q

describe a double right rotation

A

otherwise known as: right left

performed when attempting to balance a tree which has a left subtree, that is right heavy

left rotation on leftsubtree.
then a single right rotation

23
Q

describe the height balance property

A

for every node, the heights of children may differ by at most 1