C o n f i d e n t i a l HOME NEXT Subject Name: Data Structure Using C Unit Title: Trees.

Slides:



Advertisements
Similar presentations
Introduction to Trees Chapter 6 Objectives
Advertisements

Data Structures: A Pseudocode Approach with C 1 Chapter 6 Objectives Upon completion you will be able to: Understand and use basic tree terminology and.
Binary Trees Chapter 6. Linked Lists Suck By now you realize that the title to this slide is true… By now you realize that the title to this slide is.
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
CS 171: Introduction to Computer Science II
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
CS 206 Introduction to Computer Science II 09 / 22 / 2008 Instructor: Michael Eckmann.
© 2006 Pearson Addison-Wesley. All rights reserved11 A-1 Chapter 11 Trees.
CHAPTER 12 Trees. 2 Tree Definition A tree is a non-linear structure, consisting of nodes and links Links: The links are represented by ordered pairs.
Binary Trees Chapter 6.
Types of Binary Trees Introduction. Types of Binary Trees There are several types of binary trees possible each with its own properties. Few important.
Trees Chapter 8. 2 Tree Terminology A tree consists of a collection of elements or nodes, organized hierarchically. The node at the top of a tree is called.
Chapter 19: Binary Trees. Objectives In this chapter, you will: – Learn about binary trees – Explore various binary tree traversal algorithms – Organize.
Introduction Of Tree. Introduction A tree is a non-linear data structure in which items are arranged in sequence. It is used to represent hierarchical.
CS Data Structures Chapter 5 Trees. Chapter 5 Trees: Outline  Introduction  Representation Of Trees  Binary Trees  Binary Tree Traversals 
Lecture 81 Data Structures, Algorithms & Complexity Tree Algorithms GRIFFITH COLLEGE DUBLIN.
Lecture 10 Trees –Definiton of trees –Uses of trees –Operations on a tree.
Chapter 19 Implementing Trees and Priority Queues Fundamentals of Java.
Chapter 19 Implementing Trees and Priority Queues Fundamentals of Java.
Tree (new ADT) Terminology:  A tree is a collection of elements (nodes)  Each node may have 0 or more successors (called children)  How many does a.
Binary Trees, Binary Search Trees RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
Tree Data Structures.
Compiled by: Dr. Mohammad Omar Alhawarat
Trees Chapter 8. 2 Tree Terminology A tree consists of a collection of elements or nodes, organized hierarchically. The node at the top of a tree is called.
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 4. Trees.
Computer Science: A Structured Programming Approach Using C Trees Trees are used extensively in computer science to represent algebraic formulas;
Chapter 9 Binary Tree and General Tree. Overview ● Two-way decision making is one of the fundamental concepts in computing.  A binary tree models two-way.
TREES. What is a tree ? An Abstract Data Type which emulates a tree structure with a set of linked nodes The nodes within a tree are organized in a hierarchical.
CS-2852 Data Structures LECTURE 11 Andrew J. Wozniewicz Image copyright © 2010 andyjphoto.com.
Review 1 Queue Operations on Queues A Dequeue Operation An Enqueue Operation Array Implementation Link list Implementation Examples.
Tree Traversals, TreeSort 20 February Expression Tree Leaves are operands Interior nodes are operators A binary tree to represent (A - B) + C.
Lecture - 10 on Data Structures. 6:05:57 PM Prepared by, Jesmin Akhter, Lecturer, IIT,JU.
Introduction to Trees IT12112 Lecture 05 Introduction Tree is one of the most important non-linear data structures in computing. It allows us to implement.
Trees By P.Naga Srinivasu M.tech,(MBA). Basic Tree Concepts A tree consists of finite set of elements, called nodes, and a finite set of directed lines.
Discrete Mathematics Chapter 5 Trees.
M180: Data Structures & Algorithms in Java Trees & Binary Trees Arab Open University 1.
CMSC 341 Introduction to Trees. 2/21/20062 Tree ADT Tree definition –A tree is a set of nodes which may be empty –If not empty, then there is a distinguished.
Rooted Tree a b d ef i j g h c k root parent node (self) child descendent leaf (no children) e, i, k, g, h are leaves internal node (not a leaf) sibling.
© 2006 Pearson Addison-Wesley. All rights reserved11 A-1 Chapter 11 Trees.
1 Trees General Trees  Nonrecursive definition: a tree consists of a set of nodes and a set of directed edges that connect pairs of nodes.
CMSC 202, Version 5/02 1 Trees. CMSC 202, Version 5/02 2 Tree Basics 1.A tree is a set of nodes. 2.A tree may be empty (i.e., contain no nodes). 3.If.
Foundation of Computing Systems Lecture 4 Trees: Part I.
BINARY TREES Objectives Define trees as data structures Define the terms associated with trees Discuss tree traversal algorithms Discuss a binary.
TREES General trees Binary trees Binary search trees AVL trees Balanced and Threaded trees.
1 Trees. 2 Trees Trees. Binary Trees Tree Traversal.
Tree Representation and Terminology Binary Trees Binary Search Trees Pointer-Based Representation of a Binary Tree Array-Based Representation of a Binary.
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 4. Trees.
Trees Chapter 15.
CSCE 210 Data Structures and Algorithms
Lecture 1 (UNIT -4) TREE SUNIL KUMAR CIT-UPES.
Data Structures Binary Trees 1.
Chapter 11 Trees © 2011 Pearson Addison-Wesley. All rights reserved.
Csc 2720 Instructor: Zhuojun Duan
Section 8.1 Trees.
Lecture 18. Basics and types of Trees
Binary Trees, Binary Search Trees
Binary Tree and General Tree
Binary Tree and General Tree
TREES General trees Binary trees Binary search trees AVL trees
CS223 Advanced Data Structures and Algorithms
Introduction to Trees IT12112 Lecture 05.
CSE 373, Copyright S. Tanimoto, 2002 Binary Trees -
Binary Trees, Binary Search Trees
Trees.
CSE 373, Copyright S. Tanimoto, 2001 Binary Trees -
Chapter 20: Binary Trees.
Binary Trees.
Binary Trees, Binary Search Trees
Data Structures Using C++ 2E
NATURE VIEW OF A TREE leaves branches root. NATURE VIEW OF A TREE leaves branches root.
Presentation transcript:

C o n f i d e n t i a l HOME NEXT Subject Name: Data Structure Using C Unit Title: Trees

C o n f i d e n t i a l Developed By Nitendra Definition of Tree Terminologies Type of Trees – Complete Binary TreeComplete Binary Tree – Full/Strictly Binary TreeFull/Strictly Binary Tree – Binary Search TreeBinary Search Tree – Threaded Binary TreeThreaded Binary Tree – Red Black TreeRed Black Tree – B Tree [Balance Tree]B Tree [Balance Tree] – AVL TreeAVL Tree Binary Tree Traversals Application of Trees Class summary Trees NEXT PREVIOUS

C o n f i d e n t i a l Developed By Nitendra Definition of Tree : A general Tree T is a finite nonempty set of elements having unique connection between any pair of vertices. The set of elements are called vertices and connections are called edges. Trees A B C D E F G Tree T HOME NEXT PREVIOUS

C o n f i d e n t i a l Developed By Nitendra Trees Terminologies: BFE CDGH Internal node A root leaf parent child Grand Parent General Tree edge HOME NEXT PREVIOUS

C o n f i d e n t i a l Developed By Nitendra Trees Terminologies: Vertex: The vertex is the set of non empty elements with some value or weight. The plural form of vertex is vertices Edge: The connectivity between two edges called edge Root: The root is a special type of vertex having no parents Level of a vertex: The level of a vertex is the measured as the distance from the root and root is considered as the level 1. Degree of a vertex: The number of edges connected to that vertex HOME NEXT PREVIOUS

C o n f i d e n t i a l Developed By Nitendra Trees Type of Trees: Binary Tree Complete Binary Tree Full/Strict Binary Tree Binary Search Tree Threaded Binary Tree Red Black Tree B - Tree AVL Tree HOME NEXT PREVIOUS

C o n f i d e n t i a l Developed By Nitendra Trees Binary Tree A binary tree T is defined as a finite set of elements, called nodes such that T is empty, called NULL tree or empty tree T contains a distinguished node R, called root of T and the remaining nodes of T form an ordered pair of disjoint binary tree T1 and T2. The node contain max two children Examples: HOME NEXT PREVIOUS

C o n f i d e n t i a l Developed By Nitendra Trees Complete Binary Tree A full binary tree in which the number of nodes at any level i is 2 i-1, then the tree is said to be a complete binary tree. The complete binary tree is given below. In a complete binary tree, the total number of nodes at level 0 is 1 i.e., 2° Number of nodes at level 1 is 2 i.e., 2 1 Number of nodes at level 2 is 4 i.e., 2 2 Total number of nodes - = 2° ………….2 d = 2 d A B C E D H I J K F G L M N O HOME NEXT PREVIOUS

C o n f i d e n t i a l Developed By Nitendra Trees Full/Strictly Binary Tree If the degree of every node in a tree is either 0 or 2, then the tree is said to be full/strictly binary tree i.e., each node can have maximum two children or empty left and empty right child. Examples: F G B A C D E HOME NEXT PREVIOUS

C o n f i d e n t i a l Developed By Nitendra Trees Binary Search Tree A binary tree T is called a binary search tree or binary sorted tree if each node N of Tree has the following properties: The value at N is grater than every value in the left sub tree of N and is less than every value in the right sub tree of N. No duplicate value is available in Binary Search Tree. HOME NEXT PREVIOUS

C o n f i d e n t i a l Developed By Nitendra Trees Threaded Binary Tree A binary tree is threaded by making all right child pointers that would normally be null point to the inorder successor of the node, and all left child pointers that would normally be null point to the inorder predecessor of the node. HOME NEXT PREVIOUS

C o n f i d e n t i a l Developed By Nitendra Trees Red Black Tree A red-black tree is a binary search tree where each node has a color attribute, the value of which is either red or black. In addition to the ordinary requirements imposed on binary search trees, the following additional requirements of any valid red-black tree apply. - A node is either red or black. - The root is black. (This rule is used in some definitions and not others. Since the root can always be changed from red to black but not necessarily vice- versa this rule has little effect on analysis.) - All leaves are black, even when the parent is black (The leaves are the null children.) - Both children of every red node are black. HOME NEXT PREVIOUS

C o n f i d e n t i a l Developed By Nitendra Trees - Every simple path from a node to a descendant leaf contains the same number of black nodes, either counting or not counting the null black nodes. (Counting or not counting the null black nodes does not affect the structure as long as the choice is used consistently.) HOME NEXT PREVIOUS

C o n f i d e n t i a l Developed By Nitendra Trees B Tree [Balance Tree] Unlike a binary-tree, each node of a B-Tree may have a variable number of keys and children. The keys are stored in non-decreasing order. Each key has an associated child that is the root of a sub tree containing all nodes with keys less than or equal to the key but greater than the preceding key. A node also has an additional rightmost child that is the root for a sub tree containing all keys greater than any keys in the node. -The order of B Tree implies maximum number of values can be added into a single node. - If the order is 3 then maximum 3 values can be added and 4 links. HOME NEXT PREVIOUS

C o n f i d e n t i a l Developed By Nitendra Trees Example 2: Simple Diagram Example 1: Detail Diagram HOME NEXT PREVIOUS

C o n f i d e n t i a l Developed By Nitendra Trees AVL Tree The AVL tree is named after its two inventors, G.M. Adelson-Velsky and E.M. Landis, who published it in their 1962 paper "An algorithm for the organization of information“. It is the special types of Balanced Binary Search Tree. There is the Balanced Factor (BF) that must be -1, 0 or +1 for each node. Balanced Factor(BF) = Left Height – Right Height HOME NEXT PREVIOUS

C o n f i d e n t i a l Developed By Nitendra Trees Binary Tree Traversals: Traversing is the most common operation that can be performed on trees. In the traversal technique each node in the tree is processed or visited exactly once systematically one after the other. The different traversal techniques are there. Each traversal technique can be expressed recursively. There are three types of tree traversals Preorder Inorder Postorder HOME NEXT PREVIOUS

C o n f i d e n t i a l Developed By Nitendra Trees Preorder [Root – Left – Right ] The preorder traversal of a binary tree can be recursively defined as follows - Process the root Node [N] - Traverse the Left subtree in preorder[L] - Traverse the Right subtree in preorder [R] A B C D E F G Preorder Sequence : A B D F C E G HOME NEXT PREVIOUS

C o n f i d e n t i a l Developed By Nitendra Trees Inorder [Left – Root - Right ] The preorder traversal of a binary tree can be recursively defined as follows - Traverse the Left subtree in preorder[L] - Process the root Node [N] - Traverse the Right subtree in preorder [R] A B C D E F G Inorder Sequence : F D B A E G C HOME NEXT PREVIOUS

C o n f i d e n t i a l Developed By Nitendra Trees Postorder [Left - Right – Root] The preorder traversal of a binary tree can be recursively defined as follows - Traverse the Left subtree in preorder[L] - Traverse the Right subtree in preorder [R] - Process the root Node [N] A B C D E F G Postorder Sequence : F D B G E C A HOME NEXT PREVIOUS

C o n f i d e n t i a l Developed By Nitendra Trees Application of Trees: Trees are often used in implementing games, particularly “board” games node represents a position in the board branches from a node represent all the possible moves from that position the children represent the new positions Ordered binary trees can be used to represent Expression Evaluation and evaluate arithmetic expressions if a node is a leaf, the element in it specifies the value if it is not a leaf, evaluate the children and combine them according to the operation specified by the element HOME NEXT PREVIOUS

C o n f i d e n t i a l Developed By Nitendra Class summary Definition of Tree Terminologies Type of Trees – Complete Binary Tree – Full/Strictly Binary Tree – Binary Search Tree –Threaded Binary Tree – Red Black Tree – B Tree [Balance Tree] – AVL Tree Binary Tree Traversals Application of Trees HOME PREVIOUS