EC-211 DATA STRUCTURES LECTURE 11. 2 Tree Data Structure Introduction –The Data Organizations Presented Earlier are Linear in That Items are One After.

Slides:



Advertisements
Similar presentations
COSC2007 Data Structures II Chapter 10 Trees I. 2 Topics Terminology.
Advertisements

CS Fall 2012, Lab 08 Haohan Zhu. Boston University Slideshow Title Goes Here CS Fall 2012, Lab /17/2015 Tree - Data Structure  Basic.
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
1 Chapter 10 Trees. Tree Definition 1. A tree is a connected undirected graph with no simple circuits. Theorem 1. An undirected graph is a tree if and.
1 Jake’s Pizza Shop Owner Jake Manager Chef Brad Carol Waitress Waiter Cook Helper Joyce Chris Max Len.
Binary Tree Terminology Linear versus hierarchical data Tree – connected graph with no cycles Child Parent Descendant Sibling Ancestor Leaf vs. internal.
Binary Tree B G E D I H F c A Binary tree
© 2006 Pearson Addison-Wesley. All rights reserved11 A-1 Chapter 11 Trees.
Trees Chapter 25 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Trees Chapter 23 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Joseph Lindo Trees Sir Joseph Lindo University of the Cordilleras.
COSC2007 Data Structures II
Trees & Graphs Chapter 25 Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X.
Trees. Introduction to Trees Trees are very common in computer science They come in different forms They are used as data representation in many applications.
Trees Chapter 15 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
CS Data Structures Chapter 15 Trees Mehmet H Gunes
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 10 Trees –Definiton of trees –Uses of trees –Operations on a tree.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 10: Trees Data Abstraction & Problem Solving with C++
CISC220 Fall 2009 James Atlas Lecture 13: Trees. Skip Lists.
Chapter 19 Implementing Trees and Priority Queues Fundamentals of Java.
Compiled by: Dr. Mohammad Omar Alhawarat
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;
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.
Data Structures TREES.
Trees : Part 1 Section 4.1 (1) Theory and Terminology (2) Preorder, Postorder and Levelorder Traversals.
Computer Science 112 Fundamentals of Programming II Introduction to Trees.
1 Nell Dale Chapter 8 Binary Search Trees Modified from the slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus C++ Plus Data.
Min Chen School of Computer Science and Engineering Seoul National University Data Structure: Chapter 6.
Computer Science and Software Engineering University of Wisconsin - Platteville 10. Binary Search Tree Yan Shi CS/SE 2630 Lecture Notes Partially adopted.
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.
1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.
M180: Data Structures & Algorithms in Java Trees & Binary Trees Arab Open University 1.
Binary Tree. Some Terminologies Short review on binary tree Tree traversals Binary Search Tree (BST)‏ Questions.
DATA STRUCTURE BS(IT)3rd. Tree An Introduction By Yasir Mustafa Roll No. BS(IT) Bahauddin Zakariya University, Multan.
Trees Chapter 10. CS 308 2Chapter Trees Preview: Preview: The data organizations presented in previous chapters are linear, in that items are one.
© 2006 Pearson Addison-Wesley. All rights reserved11 A-1 Chapter 11 Trees.
BINARY TREES Objectives Define trees as data structures Define the terms associated with trees Discuss tree traversal algorithms Discuss a binary.
This Lecture Intro to Tree ADT Terminologies Tree Types Tree Traversals Binary Search Tree Expression Trees.
TREES General trees Binary trees Binary search trees AVL trees Balanced and Threaded trees.
1 Nell Dale Chapter 8 Binary Search Trees Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus C++ Plus Data Structures.
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.
What is a Tree? Formally, we define a tree T as a set of nodes storing elements such that the nodes have a parent-child relationship, that satisfies the.
TREES From root to leaf. Trees  A tree is a non-linear collection  The elements are in a hierarchical arrangement  The elements are not accessible.
Chapter 10 Trees © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
Trees Chapter 15.
CSCE 210 Data Structures and Algorithms
Lecture 1 (UNIT -4) TREE SUNIL KUMAR CIT-UPES.
Fundamentals of Programming II Introduction to Trees
Chapter 11 Trees © 2011 Pearson Addison-Wesley. All rights reserved.
Tree.
Csc 2720 Instructor: Zhuojun Duan
Section 8.1 Trees.
Binary Trees, Binary Search Trees
CS223 Advanced Data Structures and Algorithms
CSE 373, Copyright S. Tanimoto, 2002 Binary Trees -
Lecture 36 Section 12.2 Mon, Apr 23, 2007
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Binary Trees, Binary Search Trees
Trees.
CSE 373, Copyright S. Tanimoto, 2001 Binary Trees -
Chapter 20: Binary Trees.
Yan Shi CS/SE 2630 Lecture Notes
Binary Trees.
Binary Trees, Binary Search Trees
Presentation transcript:

EC-211 DATA STRUCTURES LECTURE 11

2 Tree Data Structure Introduction –The Data Organizations Presented Earlier are Linear in That Items are One After Another –ADTs in This Lecture Organize Data in a Non-Linear, Hierarchical Form, Whereby an Item can Have More Than one Immediate Successor

Terminology Binary Tree: a finite set of elements that is either empty or is partitioned into three disjoint subsets. – The first subset contains a single element called the root of the tree – The other two subsets are themselves binary trees, called the left and right sub-trees of the original tree – Each element of a binary tree is called a node

4 A Binary Tree Q V T K S A E L

5 Terminology If there is an Edge from Node n to Node m, Then n is the Parent of m, and m is a (left or right) Child of n Each Node in a Tree Has at Most One Parent, and the Root of the Tree has no Parent Children of the Same parent are Called Siblings A Node That Has no Children is Called a Leaf Example Figure: –Node A is the Root of the Tree, –Nodes B and C are Children of Node A –A is an Ancestor of D, and Thus, D is a Descendant of A –B and C are Not Related by Ancestor and Descendant Relation A FED C B

6 Example: Jake’s Pizza Shop Owner Jake Manager Chef Brad Carol Waitress Waiter Cook Helper Joyce Chris Max Len

7 Owner Jake Manager Chef Brad Carol Waitress Waiter Cook Helper Joyce Chris Max Len A Tree Has a Root Node ROOT NODE

8 Owner Jake Manager Chef Brad Carol Waitress Waiter Cook Helper Joyce Chris Max Len Leaf nodes have no children LEAF NODES

9 Owner Jake Manager Chef Brad Carol Waitress Waiter Cook Helper Joyce Chris Max Len A Subtree LEFT SUBTREE OF ROOT NODE

10 Owner Jake Manager Chef Brad Carol Waitress Waiter Cook Helper Joyce Chris Max Len Terminology RIGHT SUBTREE OF ROOT NODE

11 Applications Because Trees are Hierarchical in Nature, You Can Use Them to Represent Information That Itself is Hierarchical in Nature, For Example Organization Charts and Family Trees VP Manufacturing Director Sales Director Media Relations VP Marketing VP Personnel President RoseJoseph John Jacqueline Caroline

12 Example: How many leaf nodes? Q V T K S A E L

13 Example: How many descendants of Q? Q V T K S A E L

14 Example: How many ancestors of K? Q V T K S A E L

15 Terminology Trees come in Many Shapes. Level of a Node n –If n is the Root, it is at level 0. –If n is not the Root, its Level is 1 Greater Than the Level of its Parent Depth (also called Height) of Tree –Length of the Longest Path (in terms of number of edges) From the Root to a Leaf –Maximum level of any leaf in the tree A ED C B G F A A B BCC D DE E F F G G

16 Owner Jake Manager Chef Brad Carol Waitress Waiter Cook Helper Joyce Chris Max Len A Tree Has Levels LEVEL 0

17 Owner Jake Manager Chef Brad Carol Waitress Waiter Cook Helper Joyce Chris Max Len Level One LEVEL 1

18 Owner Jake Manager Chef Brad Carol Waitress Waiter Cook Helper Joyce Chris Max Len Level Two LEVEL 2

19 Terminology Strictly Binary tree –In a strictly Binary Tree, all non-leaf Nodes Have exactly Two Children Each. Not A strictly Binary Tree A strictly Binary Tree

20 Terminology A Complete Binary Tree of Height h is a strictly binary tree all of whose leaves are at Level h A complete Binary Tree of Height 3

21 Traversals of a Binary Tree When Traversing any Binary Tree, the Algorithm has Three Choices of When to Visit the Node r: –It Can Visit r Before it Traverses both of r’s Subtrees –It Can Visit r After it Has Traversed r’s Left Subtree T L But Before it Traverses r’s Right Subtree T R –It Can Visit r After it Has Traversed Both of r’s Subtrees These Traversals are Called Preorder, Inorder, and Postorder traversals Respectively

22 Traversals of a Binary Tree Preorder Traversal 1. Visit the root 2. Traverse the Left subtree in Preorder 3. Traverse the Right subtree in Preorder

23 Preorder Traversal: J E A H T M Y ‘J’ ‘E’ ‘A’ ‘H’ ‘T’ ‘M’‘Y’ root

24 Traversals of a Binary Tree Inorder Traversal 1. Traverse the Left subtree in Inorder 2. Visit the root 3. Traverse the Right subtree in Inorder

25 Inorder Traversal: A E H J M T Y ‘J’ ‘E’ ‘A’ ‘H’ ‘T’ ‘M’‘Y’ root

26 Traversals of a Binary Tree Postorder Traversal 1. Traverse the Left subtree in Postorder 2. Traverse the Right subtree in Postorder 3. Visit the root

27 ‘J’ ‘E’ ‘A’ ‘H’ ‘T’ ‘M’‘Y’ root Postorder Traversal: A H E M Y T J