BINARY TREES Flashcards
Define and illustrate a tree
•A tree (in data structure terms)
is defined as a structure in which a set of nodes are connected together by their edges, in a parent-child relationship.
*See notes for pic
What are the different applications of tree structures
- Databases
- File systems
- Web sites
What are the characteristics of trees
• Consists of nodes connected by edges.
• Edges between the nodes represent the way the nodes are
related.
• The only way to get from node to node is to follow a path
along the edges.
What is a rooted tree
•A rooted tree is one where there is one distinguished node called the root, and every other node is connected to only one parent.
What is binary tree?
•A binary tree is one in which each node has at most two children, each called the left and right child.
Describe the following terminologies: path root and parent
• Path: Traversal from node to node along the edges results in a
sequence called path.
• Root: Node at the top of the tree.
• Parent: Any node, except root has exactly one edge running
upward to another node. The node above it is called parent.
Describe the following terminologies: child, lead and subtree
• Child: Any node may have one or more lines running
downward to other nodes. Nodes below are children.
• Leaf: A node that has no children.
• Subtree: A subtree of a tree, rooted at a particular node, is a tree consisting of that node and all its descendants.
Describe the following terminologies: external, internal node, siblings, ancestor and descendant
• Nodes with the same parent are called siblings
• An external (leaf, or terminal) node has no children
• An internal (non-terminal) node has one or more children
• If there is a path from node A to node B, then A is an ancestor of B, and B is a
descendant of A.
Describe the following terminologies: visiting, traversing, levels and keys
• Visiting: A node is visited when program control arrives at the
node, usually for processing.
• Traversing: To traverse a tree means to visit all the nodes in
some specified order.
• Levels: The level of a particular node refers to how many
generations the node is from the root. Root is assumed to be
level 0.
• Keys: Key value is used to search for the item or perform
other operations on it.
Describe the depth height and size of a tree
• The depth of a node is the length of the path from the root to the node (The root has a depth of 0.)
• The height of a node is the length of the path from the node to the deepest leaf.
• The size of a node is the number of
nodes in the subtree rooted at that node (including itself.)
*See notes for illustration
What is the difference between a general tree and a binary tree
• A general tree is a data structure in that each node can
have infinite number of children.
• Every node in a binary tree can have at most two
children
Define a balanced binary/AVL tree
A binary tree is balanced if and only if, for every node, the height of its left and right subtree differ by at most 1.
*See notes for illustration
Define a binary search tree
This is a binary tree in which the left child is always less
that its parent, while right child is greater than its parent.
What are the two ways of representing trees
1.Linked list
• Similar to Linked List but with two Links
• Store the nodes at unrelated locations in memory and
connect them using references in each node that point to its
children.
2.Arrays
• Can also be represented as an array, with nodes in specific
positions stored in corresponding positions in the array.
*See notes for illustrations
What are different ways to traverse a tree
– Inordertraversal: Left subtree, Node, Right subtree
– Preordertraversal: Node, Left subtree, Right subtree
– Postordertraversal: Left subtree, Right subtree, Node