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
expression tree
a tree that shows the relationships among operators and operands in an expression; evaluated from the bottom up
decision tree
a tree whose nodes represent decision points, and whose children represent the options available
binary search trees
elements are organized to facilitate finding a particular element when needed - the left subtree of each node n contains elements less than the element stored in n and the right subtree of each node n contains elements greater than or equal to the element stored in n
a LinkedList is more efficient than a BST for which operations?
removeFirst and first
a right rotation on a BST
- make the left child element of the root the new root element
- make the former root element the right child element of the new root
- make the right child of what was the left child of the former root the new left child of the former root
a left rotation on a BST
- make the right child element of the root the new root element
- make the former root element the left child element of the new root
- make the left child of what was the right child of the former root the new right child of the former root