Zusammenfassung der Ressource
Trees
- General Trees
- Terminology: parent, child,
ancestor, descendant
- Tree: With the exception of the top element,
each element in a tree has a parent element
and zero or more children elements
- Top element = root
- Set of nodes storing elements
- Edge: pair of nodes (u,v):
u is the parent of v
- Path: sequence of nodes
- Tree ADT
- getElement()
root()
parent(p)
children(p)
numChildren(p)
- Binary Trees
- Ordered tree
- Every node has at
most two children
- Each child is labeled as being
either left child or right child
- A left child precedes a right
child in the order of children
of a node
- Binary Tree ADT
- left(p)
right(p)
sibling(p)
- Implementing Trees
- Linked Structure
- addRoot(e)
addLeft(p,e)
addRight(p,e)
set(p,e)
remove (p)
- Tree Traversal Algorithms
- Traversal: systematic way of
accessing all the positions of the tree
- Preorder traversal: the root of T is visited
first and then the subtrees rooted at its
children are traversed recursively
- Postorden traversal: it recursively traverses
the subtrees rooted at the children of the
root first, an then visits the root
- Inorder traversal: visiting the
nodes of T from left to right