Download presentation
Presentation is loading. Please wait.
Published bySybil Lilian Washington Modified over 6 years ago
1
Lecture 1 (UNIT -4) TREE SUNIL KUMAR CIT-UPES
2
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
3
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.
4
REVIEW
5
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 It is a logical & mathematical representation of data. The organization of data element and the interrelationships among them. A data structure is a way to store and organize data in order to facilitate access and modifications
6
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.
8
Non-Linear Data Structure
Type of Data Structure Data Structure Linear Data Structure Array Linked List Stack Queue Non-Linear Data Structure Tree Graph Stack & Queue can be implemented with the help of Array and linked List
9
Nature View of Tree leaves branches root
10
Computer Vision root branches leaves
11
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. 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.
12
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
13
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 non-empty (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
14
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 E C F G D E B F G C A A B C D E F G D B E A F C G A B C D E F G A B C D E F G Source: David Matuszek
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.