Week 7: Trees and Heaps Flashcards
What are the main properties of trees in general?
Miller and Ranum first introduce the tree data structure, giving examples from biology (a taxonomy) and computing (a file system and a web page). They note three properties of trees:
a. they are hierarchical b. children of one tree node are independent of the children of another c. leaf nodes are unique.
In computing, what is a tree?
They offer two possible definitions of a tree in computing, one based on the concepts of nodes and edges, the other recursive.
Note that according to both the nodes and edges definition and the recursive definition of a tree, a tree can be empty. For the recursive definition of a tree, this is obvious. It states explicitly that trees can be empty. At first sight, the nodes and edges definition seems to exclude the possibility of an empty tree. After all, Miller and Ranum’s Definition One says that ‘One node of the tree is designated as the root node’. In fact, this formulation is misleading: it should really say: ‘One node of the tree, if the tree is non-empty, is designated as the root node’. In terms of nodes and edges, the empty tree is represented by an empty set of nodes with an empty set of edges.
What is a binary tree?
In doing so, they introduce an important special case of a tree: the binary tree – a tree in which each node has a maximum of two children.
What is the definition for a node?
A node is a fundamaental part of a tree. It can have a name, which we call the ‘key’. A node may also have additional infomration. we call this the ‘payload’ While the payload information is not central to many tree algorithms, it is often critical in applications that make use of trees.
What is the definition for an Edge?
an edge is another fundamental part of a tree. an edge connects two nodes to show that there is a relationship between them. every node (except the root) is connected by exactly one incoming edge from another node. each node may have several outgoing edges.
What is the definition for a root?
the root of the tree is the only node in the tree that has no incoming edges.
What is the definition for a Path?
A path is an ordered list of nodes that are connected by edges.
What is the definition for Children?
The set of nodes c that have incoming edges from the same node to are said to be the children of that node
What is the definition for a Parent?
A node is the parent of all the nodes it connects to with outgoing edges
What is the definition for a sibling
Nodes in the trees that are children of the same parent are said to be siblings.
What is the definition for a subtree
A subtree is a set of nodes and edges comprised of a parent and all the decendants of that parent.
What is the definition for a leaf node
A leaf node is a node that noc hildren
What is the definition for a level?
the level of a node is the number of edges on the path from the root node to n.
What does it mean to transverse a tree?
Traversing a tree simply means visiting every node in it. The difference between the three modes of traversal that Miller and Ranum present is simply the order in which they are visited.
What forms of tree traversal are available?
Three ways of traversing a tree are presented: preorder, postorder and inorder. There are many videos and visualisations of these types of traversal available on the web; you might want to search for some of these yourself.