Trees. What is a Tree? In computer science, a tree is an abstract model of a hierarchical structure A tree consists of nodes with a parent- child relation.

Slides:



Advertisements
Similar presentations
Trees and Binary Trees Become Rich Force Others to be Poor Rob Banks
Advertisements

Trees1 More on Trees University Fac. of Sci. & Eng. Bus. School Law School CS Dept. EE Dept. Math. Dept.
Data Structures Lecture 6 Fang Yu Department of Management Information Systems National Chengchi University Fall 2010.
Trees Briana B. Morrison Adapted from Alan Eugenio.
Elementary Data Structures
© 2004 Goodrich, Tamassia Trees1 Make Money Fast! Stock Fraud Ponzi Scheme Bank Robbery.
© 2004 Goodrich, Tamassia Priority Queues1 Heaps: Tree-based Implementation of a Priority Queue.
© 2004 Goodrich, Tamassia Trees1 Chapter 7 Trees Make Money Fast! Stock Fraud Ponzi Scheme Bank Robbery.
Trees1 Recursion Recursion is a concept of defining a method that makes a call to itself.
Trees - Ed. 2. and 3.: Chapter 6 - Ed. 4.: Chapter 7.
Chapter 7: Trees Objectives:
© 2004 Goodrich, Tamassia Trees1 Lecture 04 Trees Topics Trees Binary Trees Binary Search trees.
Elementary Data Structures Stacks, Queues, & Lists Amortized analysis Trees.
1 Chapter 7 Trees. 2 What is a Tree In computer science, a tree is an abstract model of a hierarchical structure A tree consists of nodes with a parent-child.
© 2004 Goodrich, Tamassia Trees1 this is a tree. © 2004 Goodrich, Tamassia Trees2 What is a Tree? In computer science, a tree is an abstract model of.
Trees COMP53 Oct 31, What is a Tree? A tree is an abstract model of a hierarchical structure A tree consists of nodes with a parent-child relation.
Trees1 Part-C Trees Make Money Fast! Stock Fraud Ponzi Scheme Bank Robbery.
CSC401 – Analysis of Algorithms Lecture Notes 4 Trees and Priority Queues Objectives: General Trees and ADT Properties of Trees Tree Traversals Binary.
Tree properties and traversals
General Trees. Tree Traversal Algorithms. Binary Trees. 2 CPSC 3200 University of Tennessee at Chattanooga – Summer 2013 © 2010 Goodrich, Tamassia.
Trees Chapter 8.
Trees.
Make Money Fast! Stock Fraud Apply shortcuts Bank Robbery Just For Laughs Trees This one is cool eITnotes.com For more notes and topics visit:
Trees CSCI 3333 Data Structures. Acknowledgement  Dr. Bun Yue  Mr. Charles Moen  Dr. Wei Ding  Ms. Krishani Abeysekera  Dr. Michael Goodrich  Dr.
Chapter 7:Trees Nancy Amato Parasol Lab, Dept. CSE, Texas A&M University Acknowledgement: These slides are adapted from slides provided with Data Structures.
Saturday, 04 Apr 2010 University of Palestine Computer Science II Trees.
Trees 4/23/2017 Trees.
COMP20010: Algorithms and Imperative Programming Lecture 1 Trees.
© 2004 Goodrich, Tamassia Trees1 Text Book: M. T. Goodrich and R. Tamassia, "Data Structures and Algorithms in Java," 4th edition, 2006, Wiley & Sons,
Trees by Dr. Bun Yue Professor of Computer Science CSCI 3333 Data Structures.
1 Today’s Objectives  Announcements Hand in Homework 3 next week  Iterators  Trees Tree terminology Depth and height Preorder and postorder traversals.
Trees1 Make Money Fast! Stock Fraud Ponzi Scheme Bank Robbery © 2010 Goodrich, Tamassia.
Lecture11: Tree I Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)
Data Structures & Algorithm Analysis Muhammad Hussain Mughal Trees. Binary Trees. Reading: Chap.4 ( ) Weiss.
Trees1 Make Money Fast! Stock Fraud Ponzi Scheme Bank Robbery © 2010 Goodrich, Tamassia.
Trees1 Make Money Fast! Stock Fraud Ponzi Scheme Bank Robbery © 2013 Goodrich, Tamassia, Goldwasser.
Trees trees binary trees traversals of trees template method pattern
CH 7. TREES ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA AND MOUNT (WILEY.
24 January Trees CSE 2011 Winter Trees Linear access time of linked lists is prohibitive  Does there exist any simple data structure for.
CH 7 : TREE ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA AND MOUNT (WILEY.
Trees1 Make Money Fast! Stock Fraud Ponzi Scheme Bank Robbery © 2010 Goodrich, Tamassia.
© 2004 Goodrich, Tamassia Trees1 Make Money Fast! Stock Fraud Ponzi Scheme Bank Robbery.
Trees Data Structures and Algorithms CS 244 Brent M. Dingle, Ph.D. Department of Mathematics, Statistics, and Computer Science University of Wisconsin.
TREE Ahsan Ahmed College of Computer and Information Science Majma’ah University 1.
1 COMP9024: Data Structures and Algorithms Week Five: Trees Hui Wu Session 1, 2015
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.
Elementary Data Structures
Trees Make Money Fast! Stock Fraud Ponzi Scheme Bank Robbery
Trees 5/2/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser,
Trees 5/10/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser,
Searching (and into Trees)
Lecture 1 (UNIT -4) TREE SUNIL KUMAR CIT-UPES.
Trees Make Money Fast! Stock Fraud Ponzi Scheme Bank Robbery Trees
University of Palestine
Trees 二○一八年八月二十六日 Part-C Trees Trees.
Trees 9/21/2018 9:58 PM Trees this is a tree Trees.
Trees Make Money Fast! Stock Fraud Ponzi Scheme Bank Robbery
Trees and Binary Trees.
Trees Make Money Fast! Stock Fraud Ponzi Scheme Bank Robbery
Trees Make Money Fast! Stock Fraud Ponzi Scheme Bank Robbery
Elementary Data Structures
Week nine-ten: Trees Trees.
Trees Make Money Fast! Stock Fraud Ponzi Scheme Bank Robbery Trees
Trees "A tree may grow a thousand feet tall, but its leaves will return to its roots." -Chinese Proverb CLRS, Section 10.4.
Trees Palestine Gaza West Bank 48 Stolen Land Trees Trees
Lecture 8: Iterators, Trees
Copyright © Aiman Hanna All rights reserved
CS210- Lecture 9 June 20, 2005 Announcements
Trees Make Money Fast! Stock Fraud Ponzi Scheme Bank Robbery
Trees.
Presentation transcript:

Trees

What is a Tree? In computer science, a tree is an abstract model of a hierarchical structure A tree consists of nodes with a parent- child relation Applications: – Organization charts – File systems – Programming environments

What is a Tree? Computers”R”Us SalesHRManufacturing LaptopsDesktops US International EuropeAsiaCanada

Tree Terminology Root: node without parent (A) Internal node: node with at least one child (A, B, C, F) External node (a.k.a. leaf ): node without children (E, I, J, K, G, H, D) Ancestors of a node: parent, grandparent, grand- grandparent, etc. Depth of a node: number of ancestors Height of a tree: maximum depth of any node (3) Descendant of a node: child, grandchild, grand- grandchild, etc. Subtree: tree consisting of a node and its descendants

subtree Tree Terminology A B DC GH E F IJ K ancestors of I, J and K descendants of A

Use of Trees In most OS’s, files are organized hierarchically into folders, and presented in the form of trees. A structured document, such as a book is hierarchically organized as a tree – ordered tree Arithmetic expressions can be represented by an expression tree. Different outcomes in a result can be represented by a decision tree

Tree ADT We use positions to abstract nodes Generic methods: – integer size() – boolean isEmpty() – objectIterator elements() – positionIterator positions() Accessor methods: – position root() – position parent(p) – positionIterator children(p)

Tree ADT Query methods: – boolean isInternal(p) – boolean isExternal(p) – boolean isRoot(p) Update methods: – swapElements(p, q) – object replaceElement(p, o) Additional update methods may be defined by data structures implementing the Tree ADT

Algorithm Analysis on the Operations of the Tree isEmpty() O(1) size() O(1) elements() O(n) positions() O(n) root() O(1) parent() O(1) children( pos ) O(c)* isInternal() O(1) isExternal() O(1) isRoot() O(1) swapElements( w, x ) O(1) replaceElement( pos, e ) O(1) * c represents the number of children

Structure of a Tree The tree is a structure that stores information in a parent-child structure. This results in a recursive formation – that is, the root node creates a tree, and each child of the root node creates a sub-tree, and each child in each of those nodes creates other sub-trees.

Structure of a Tree This ‘recursive’ format of a tree structure gives rise to writing recursive algorithms for some functionality. For instance, to find the depth of a node all that is necessary is to find the number of parents all the way to the root node. There is no necessity to visit all then nodes in the tree.

Depth of a Tree Depth of v = number of ancestors of v If v is the root v’s depth = 0 else v’s depth = 1 + depth of v’s parent v w x y z v = 0 w = 1 + depth( myParent ) = = 1 x = 1 + depth( myParent ) = = 2 y = z = 1 + depth( myParent ) = = 3

Finding the Depth int depth( const Tree& T, const Position& v ) { if( T.isRoot(v) ) return 0; else return 1 + depth( T, T.parent(v) ); }

Big-O of the depth function The big-O of this function would depend on how the tree is created. If the tree is lop-sided, then in the worse case scenario the big- O would be O(n), but if the tree is balanced, the worse case would be O(logn)

Height Height of node v If v is an external node v’s height = 0 else v’s height = 1 + maximum height of v’s children h v = 1 + max( h of myChildren ) h v = = 2 v h = 0 (external node) h = 1 + max( h of myChildren ) h = = 1 h = 0

Finding the Height of a Tree Algorithm height( T, root ) if T.isExternal(root) then return 0 else h = 0 for each node  T.children(root) do h = max( h, height(T,node) ) return 1 + h r u t v 1 2 T 00