A tree is a combination of a finite set of elements, called nodes and a finite set of directed lines, called branches that connect the nodes.
Some important terms:
- Root node: If the tree is non empty, then the first node is called as root. The indegree of root by definition is zero.
- Leaf node: A node with no successors (nodes after it). There will usually be many leaves in a tree.
- Non Leaf node: A node which has both a parent and at least one child.
- Internal nodes: Nodes that are not root and not leaf are called as internal nodes
- Parent node: A node is a parent if it has successor nodes; means out degree greater than zero.
- Child node: A node is child node if indegree is one.
- Siblings: Two or more nodes with same parent are siblings.
- Ancestor node: An ancestor is any node in the path from the root to the node.
- Descendant node: A descendent is any node on the path below the parent node.
- Subtree: A subtree is any connected structure below the root.
- Directed tree: A directed tree is an acyclic digraph, which has only one node with indegree 0, and others nodes have indegree 1.
- Binary tree: A binary tree is a tree in which no node can have more than two subtrees. In other word it is a directed tree in which outdegree of each node is less than or equal to two. (i.e. zero, one or two). An empty tree is also a binary tree.
- Strictly binary tree: If the outdegree of every node in a tree is either 0 or 2, then the tree is said to be strictly binary tree. i.e. each node can have maximum two children or empty left and empty right child.
- Complete binary tree: A strictly binary tree in which the number of nodes at any level i is 2 i-1 then the tree is said to be complete binary tree.
- Almost binary tree: A tree of depth d is an almost complete binary tree, if the tree is complete up to the level d-1.
- Tree traversals: Tree traversal is the technique in which each node in the tree is processed or visited exactly once systematically one after the other. The different tree traversal techniques are Inorder, Preorder and Postorder.Algorithm for tree traversal
- Traverse the left sub tree in inorder [L]
- Process the root node [N]
- Traverse the right sub tree in inorder [R]
- Process the root node [N]
- Traverse the left sub tree in preorder [L]
- Traverse the right sub tree in Preorder [R]
- Traverse the left subtree in post order. [L]
- Traverse the Right sub tree in postorder [R]
- Process the root node [N]
The operations performed on binary search tree are:
- Insertion: An item is inserted
- Searching: Search for a specific item in the tree.
- Deletion: Deleting a node from a given tree.
You Might also view the following Related Posts
- Fundamental of data structures
- Definition of Stack
- Definition of Queues
- Definition of List and Linked List
- Graph Definition
إرسال تعليق
Click to see the code!
To insert emoticon you must added at least one space before the code.