Lecture 1 (UNIT -4) TREE SUNIL KUMAR CIT-UPES | Jan 2016| © 2012 UPES Objectives of Unit -2 After completion of this unit, You will be able to: Understand the fundamentals of Tree Data Structure. Understand concepts of Binary tree and its operations Jan Jan2016 2016 © 2012 UPES Objectives of Today’s Lecture After completion of today’s Lecture, You will be able to : Understand the basic terminologies of tree data structure Understand the fundamentals of binary tree. Jan Jan2016 2016 © 2012 UPES REVIEW Jan Jan2016 2016 © 2012 UPES Data Structure What is Data Structure ? Data Structure = Data + Structure Data – Atomic (single and non decomposable entity) – or Composite (broken into subfields that have meaning) Structure –A set of rules that holds the data together 1. It is a logical & mathematical representation of data. 2. The organization of data element and the interrelationships among them. 3. A data structure is a way to store and organize data in order to facilitate access and modifications Jan Jan2016 2016 © 2012 UPES Data Structure Data Structure also describe that ► How efficiently data store, access, manage. ► Data structures effect algorithm’s performance No single data structure works well for all purposes, and so it is important to know the strengths and limitations of several of them. Jan Jan2016 2016 © 2012 UPES 7 Jan 2016 © 2012 UPES Type of Data Structure Data Structure Linear Data Structure Array Linked List Non-Linear Data Structure Stack Queue Tree Graph Stack & Queue can be implemented with the help of Array and linked List Jan Jan2016 2016 © 2012 UPES Nature View of Tree leaves branches root Jan Jan2016 2016 © 2012 UPES Computer Vision root branches leaves Jan Jan2016 2016 © 2012 UPES Tree Terminologies Root: node without parent (A) Siblings: nodes share the same parent Internal node: node with at least one child (A, B, C, F) External node (leaf ): node without children (E, I, J, K, G, H, D) Ancestors of a node: parent, grandparent, grand-grandparent, etc. Descendant of a node: child, grandchild, grand-grandchild, etc. Depth of a node: number of ancestors Height of a tree: maximum depth of any node (3) Degree of a node: the number of its children Degree of a tree: the maximum number of its node. Jan Jan2016 2016 Subtree: tree consisting of a node and its descendants A path from node n1 to nk is defined as a sequence of nodes n1, n2, …, nk such that ni is the parent of ni+1 for 1<= i <= k. © 2012 UPES Tree Properties Property Value Number of nodes Height Root Node Leaves Interior nodes Ancestors of H Descendants of B Siblings of E Right subtree of A Degree of this tree Jan Jan2016 2016 © 2012 UPES Tree and its properties A tree nonlinear data structure with finite nonempty set of elements. It is an abstract model of a hierarchical structure consists of nodes with a parent-child relation. Tree defined recursively A tree is a collection of nodes. The collection can be empty; otherwise, a tree consists of a distinguished node r, called the root, and zero or more nonempty (sub) trees T1, T2, …, Tk each of whose roots are connected by a directed edge from r. A tree is a collection of N nodes, one of which is the root and N-1 edges. Applications: ► Organization charts ► File systems ► Programming environments Jan Jan2016 2016 © 2012 UPES Tree traversals using “flags” • The order in which the nodes are visited during a tree traversal can be easily determined by imagining there is a “flag” attached to each node, as follows: preorder inorder postorder • To traverse the tree, collect the flags: A B D C E F ABDECFG Source: David Matuszek A A B G D B C E F DBEAFCG G D C E F DEBFGCA G
© Copyright 2026 Paperzz