COMP 2210 Module 14 - Search Trees
balance factor avl formula
BFm = Hr - Hl
a ______ tree will have near-optimal height for storing N nodes
balanced
deleting an element from an AVL tree
beginng atthe point of deletion, walk the reverse path back toward the root, recalculating balance factors stop at the first (lowest) node that has a balance factor of +-2. this node roots the 3-node neighborgood that will be rotated
avl search tree
binary search tree in which the heights of the left and right subtree of every node differ by at most one
a ______ node has exactly one _______
child parent
branches
connections between nodes, from parent to child. also called edges
preorder, inorder, and postorder are all _fs
d
case for deletion: the value is in a node with two non-empty subtrees
don't delete the node. find a replacement for this node's value and delete the node containing the replacement
ternary tree
each node can have at most 3 children
red black tree 4 rules
each node is either red or black the root and all empty trees are black all paths from the root to an empty tree contain the same number of black nodes a red node can't have a red child
binary search tree order
everything to the left is less everything to the right is greater than
a ______ node has no _______
leaf children
height
longest path from a given node to a descendant leaf
2-4 tree
m-way each non-leaf node must have at leats two non-empty subtrees
depth
measures the distance of a given node from the top of the tree. essentially level
descendant
node x is a descendant of node y if there is a path from y to x
ancestor
node x is an ancestor of rode y if there is a pth from x to y
a tree is composed of _____ and ______
nodes branches
binary search tree searching
o(height) height = n if tall and narrow height = logn if short and wide
worse case binary tree insert
o(height) inserting it as a child of the lowet leaf
height is
o(logn) for full, complete, balanced?
list is a _____ ________ structure because it defines linear relationships between elements: predecessor, successor
one dimensional
a _______ node has one or more ________
parent children
node
place in the tree where the elements are stored
multiple ________ operations may be required per deletion, so the reverse walk must go to the root each time
rebalancing
a ___ _____ is used like a filler. it allows a red-black tree to obey rules 1, 2, and 3 without being a perfect triangle (full)
red node
without ____ ______, red-black trees could only be full
red nodes
the _____ node has no _____
root parent
case for deletion: the value to delete is in a leaf node
set the parent's pointer to this node to null
case for deletion: the value to delete is in a node with exactly one non-empty subtree
set the parent's pointer to this node to this node's child
incremental balancing
the insert and delete algorithms are modified to ensure that the tree is balanced after each operation that could affect its height. trees that use incremental balancing are called self-balancing BSTs
path length
the number of nodes on the path
periodic balancing
the tree grows naturally without regard for its height or shape. at some interval (ether when a height threshold is reached or just on demand), the tree is reorganized to reduce its height to o(log n). the cost of this operation is amortized over many inserts and deletes
random adds
tree should be relatively flat
random removes
tree structure is bad. search and add becomes root of N
tree is a ____ __________ structure because it defines hierarchical relationships among elements: parent, child
two dimensional
m-way trees are different because they grow ___
up
bfs strategy
visit the nodes level by level
binary tree inorder
LNR left node right
binary tree post order
LRN left right node
binary tree preorder
NLR node left right
tree
a collection in which the elements are arranged in a hirearchy
path length note
a path is sometimes defined as a sequence of edges instead of nodes so path length is sometimes counted differently
path
a sequence of nodes from one node to another node, going from parent to child
balanced
a tree is balanced if for each node, its sub trees have similar heights
complete
a tree is complete if it is full to the next to last level, and the leaves on the lowest level are "left justified"
multi-way search tree
a tree of order m > 2 in which the search property (total order) holds on every node and in which all leaves are at the same depth
subtree
a tree within a larger tree, rooted at the given node x. the subtree consists of x and all descents of x. the tree itself is a subtree
full tree
all leaves have the same depth and every parent node has the maximum number of children