Binary Trees Flashcards
give the Tree ADT
e = element, v = node
root() insert(e) remove(v) find(e) parent(v) children(v) elements() isExternal(v)
describe the binary Tree ADT
at most two children. children replaced with left and right adds sibling(v)
what is depth and what is height
depth, number of ancestors excluding self
height, maximal depth
what is a proper/full binary tree
either 0 or 2 children
what is a complete tree
all levels full, except for last, where all nodes are as far left as possible
what is a perfect tree
proper tree where all external nodes have equal depth
what is an ordered tree
all elements left < right and stored element, and stored element < right
what is a sparse tree
lots of empty elements
how would a binary tree be represented using vector (array) represenation
A[0] = root
parent = A[(k-1)/2]
left child = A[2k+1]
right child = A[2k+2]
how would a binary tree be represented in a linked structure
each node has: value, left pointer, right pointer
what is a traversal
systematic way of visiting each node
describe pre-order traversal
node then children
describe post-order traversal
children then node
describe in-order traversal
left then node then right
describe depth first search
search children before sibling