Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Trees krw


Published on

Published in: Technology, Business
  • Be the first to comment

  • Be the first to like this

Trees krw

  1. 1. TreesKasun Ranga Wijeweera(Email:
  2. 2. What is a Tree?• A two dimensional linked structure• Examples:– Family tree– Organization of sports tournament– Organizational chart of large cooperation
  3. 3. A Tree• A tree is a nonempty collection of vertices and edges thatsatisfies certain requirements• A vertex is a simple object (also referred to as a node) that canhave a name and carry other associated information• An edge is a connection between two vertices• A path in a tree is a list of distinct vertices in which successivevertices are connected by edges in the tree• One node in the tree is designated as the root• The defining property of a tree is that there is exactly one pathbetween the root and each of the other nodes in the tree
  4. 4. A Sample Tree: Figure 1
  5. 5. Details• Each node (except the root) has exactly one node above it,which is called its parent• The nodes directly below a node are called its children• In Figure 1, P is the grandchild of R and has three siblings• Nodes with no children are sometimes called leaves, orterminal nodes• Nodes with at least one child are called non terminal nodes• Sometimes we refer to non terminal nodes as internal nodesand terminal nodes as external nodes
  6. 6. A Sub Tree• Any node is the root of a sub tree consisting of it and the nodesbelow it• In Figure 1, there are– seven one-node sub trees– one three-node sub tree– one five-node sub tree– one six-node sub tree
  7. 7. A Forest• A set of trees is called a forest• For example, if we remove the root and the edges connecting itfrom the tree in Figure 1, we are left with a forest consisting ofthree trees rooted at A, R, and E
  8. 8. An Ordered Tree• An ordered tree is one in which the order of the children atevery node is specified• There are many different ways to draw trees that are notordered
  9. 9. Levels of a Tree• The level of a node is the number of nodes on the path fromthe node to the root (not including itself)• For example, in Figure 1, R is on level 1 and S is on level 2• The height of a tree is the maximum level among all nodes inthe tree (or maximum distance to the root from any node)• The path length of a tree is the sum of the levels of all thenodes in the tree (or the sum of the lengths of the paths fromeach node to the root)• The tree in Figure 1 is of height 3 and path length 21• If internal nodes are distinguished from external nodes, wespeak of internal path length and external path length
  10. 10. A Multi Way Tree• If each node must have a specific number of childrenappearing in a specific order, then we have a multi way tree• In such a tree, it is appropriate to define special external nodeswhich have no children (and usually no name or otherassociated information)• Then external nodes act as “dummy” nodes for reference bynodes that do not have the specified number of children
  11. 11. A Binary Tree• A binary tree is an ordered tree consisting of two types ofnodes: external nodes with no children and internal nodes withexactly two children• Since the two children of each internal node are ordered, werefer to the left child and the right child of internal nodes• Every internal node must have both a left and a right child,though one or both of them might be an external node
  12. 12. A Sample Binary Tree: Figure 2
  13. 13. Binary Tree Details• The purpose of the binary tree is to structure the internalnodes; the external nodes serve only as placeholders• A binary tree could be “empty”, consisting of no internalnodes and one external node
  14. 14. Reference
  15. 15. Any Questions?
  16. 16. Thank You!