CSCI 211 Test 2 Flashcards
a tree is a
non-linear structure in which elements are organized into a hierarchy; it is comprised of a set of nodes in which elements are stores and edges connect one node to another, and each node is located on a particular level
a node can have ? parent(s)
only one
a node with no children
leaf node
not the root node or a leaf node
internal node
a subtree is
a tree structure that makes up part of a larger tree
one important criterion for classifying trees is
the number of children it can have
defining trees (3 things)
- Nodes connected by edges
- Can be classified by max # children
- Do not have cycles or “loops” - they are recursive structures
binary tree
tree in which nodes have at most two children
a tree is balanced if
all of the leaves of the tree are on the same level or within one level of each other
a balanced n-ary tree with m elements will have a height of
log base n of m
a tree is complete if
it is full, or full to the next-to-last level with all leaves af the bottom level on the left side of the tree
all tree traversals start at the ? of the tree
root
each node can be thought of as the ? of a subtree
root
list the four classic types of tree traversals
- Preorder
- Inorder
- Postorder
- Level-order
Preorder
Visit the root, then traverse the subtrees left to right
Inorder
Traverse the left subtree, then visit the root, then traverse the right subtree
Postorder
Traverse the subtrees from left to right, then visit the root
Level-order
Visit each node at each level of the tree from top to bottom and left to right