Trees.

Slides:



Advertisements
Similar presentations
Chapter 10: Trees. Definition A tree is a connected undirected acyclic (with no cycle) simple graph A collection of trees is called forest.
Advertisements

EC-211 DATA STRUCTURES LECTURE Tree Data Structure Introduction –The Data Organizations Presented Earlier are Linear in That Items are One After.
CS 171: Introduction to Computer Science II
Binary Tree Terminology Linear versus hierarchical data Tree – connected graph with no cycles Child Parent Descendant Sibling Ancestor Leaf vs. internal.
© 2006 Pearson Addison-Wesley. All rights reserved11 A-1 Chapter 11 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.
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.
CSC 2300 Data Structures & Algorithms February 6, 2007 Chapter 4. Trees.
Joseph Lindo Trees Sir Joseph Lindo University of the Cordilleras.
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.
Trees CSCI 3333 Data Structures. Acknowledgement  Dr. Bun Yue  Mr. Charles Moen  Dr. Wei Ding  Ms. Krishani Abeysekera  Dr. Michael Goodrich  Dr.
CS Data Structures Chapter 5 Trees. Chapter 5 Trees: Outline  Introduction  Representation Of Trees  Binary Trees  Binary Tree Traversals 
Tree ADTs Tree concepts. Applications of Trees. A Tree ADT – requirements, contract. Linked implementation of Trees. Binary Tree ADTs. Binary Search.
Compiled by: Dr. Mohammad Omar Alhawarat
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 4. Trees.
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.
Data Structures TREES.
Data Structures & Algorithm Analysis Muhammad Hussain Mughal Trees. Binary Trees. Reading: Chap.4 ( ) Weiss.
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 Storing Hierarchical Information Lists, Stacks, and Queues represent linear sequences Data often contain hierarchical relationships that cannot be expressed.
Tree Traversals, TreeSort 20 February Expression Tree Leaves are operands Interior nodes are operators A binary tree to represent (A - B) + C.
Min Chen School of Computer Science and Engineering Seoul National University Data Structure: Chapter 6.
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.
M180: Data Structures & Algorithms in Java Trees & Binary Trees Arab Open University 1.
24 January Trees CSE 2011 Winter Trees Linear access time of linked lists is prohibitive  Does there exist any simple data structure for.
© 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.
TREES General trees Binary trees Binary search trees AVL trees Balanced and Threaded trees.
© 2004 Goodrich, Tamassia Trees1 Make Money Fast! Stock Fraud Ponzi Scheme Bank Robbery.
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.
1 Trees : Part 1 Reading: Section 4.1 Theory and Terminology Preorder, Postorder and Levelorder Traversals.
Trees CSIT 402 Data Structures II 1. 2 Why Do We Need Trees? Lists, Stacks, and Queues are linear relationships Information often contains hierarchical.
Trees A non-linear implementation for collection classes.
1 Trees. 2 Trees Trees. Binary Trees Tree Traversal.
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.
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 4. Trees.
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,
Chapter 10 Trees © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
CSCE 210 Data Structures and Algorithms
Lecture 1 (UNIT -4) TREE SUNIL KUMAR CIT-UPES.
Trees Make Money Fast! Stock Fraud Ponzi Scheme Bank Robbery
Trees Make Money Fast! Stock Fraud Ponzi Scheme Bank Robbery Trees
Trees 二○一八年八月二十六日 Part-C Trees Trees.
Tree.
Section 8.1 Trees.
Binary Trees, Binary Search Trees
Trees 9/21/2018 9:58 PM Trees this is a tree Trees.
TREES General trees Binary trees Binary search trees AVL trees
CS223 Advanced Data Structures and Algorithms
COSC2100: Data Structures and Algorithms
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
Week nine-ten: Trees Trees.
Trees Definitions Implementation Traversals K-ary 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
CSE 373, Copyright S. Tanimoto, 2002 Binary Trees -
CMSC 202 Trees.
Lecture 36 Section 12.2 Mon, Apr 23, 2007
CSE 373, Copyright S. Tanimoto, 2001 Binary Trees -
Tree.
CS210- Lecture 9 June 20, 2005 Announcements
Trees Make Money Fast! Stock Fraud Ponzi Scheme Bank Robbery
Binary Trees.
NATURE VIEW OF A TREE leaves branches root. NATURE VIEW OF A TREE leaves branches root.
Presentation transcript:

Trees

What is a Tree? 10/18/2019

What is a Tree? Trees are an important data structure They organize data hierarchically They are used to model hierarchical data in the real world store and retrieve data 10/18/2019

A hierarchical organization of a hypothetical company Computers”R”Us Sales R&D Manufacturing Laptops Desktops Local International Europe Asia Africa A hierarchical organization of a hypothetical company 10/18/2019

Tree Terminology Node Child Parent Data stored in the tree A node descended from another node Parent The node from which another node descended a c b a is the parent of both b & c b & c are children of a 10/18/2019

Tree Terminology Root The node from which all others descend Branch Joins nodes Leaf (External node ) A node without children Degree=3 Maximum # of children Siblings Children of a common parent 10/18/2019

Tree Terminology Ancestors of a node Descendant of a node Any node from which a node descended (parent, grandparent, grand-grandparent, etc). Descendant of a node Any child, grandchild, grand-grandchild, etc. Depth of a node Number of ancestors 10/18/2019

Tree Terminology Height of a tree Subtree Path Maximum depth of any node Subtree Tree consisting of a node and its descendants Path The set of branches connecting an ancestor to a descendant 10/18/2019

Tree Terminology Depth = 0 Depth = 2 Depth = 3 Subtree 10/18/2019

Trees vs. Graphs A tree Cannot contain cycles Each node has 1 parent or it is at the root Any structure which does not meet these criteria is a graph The structures to the right are graphs 10/18/2019

Review: Recursive definition of list Empty list (0 nodes) OR Head node and 0 or 1 non-empty sublist 10/18/2019

Recursive definition of Tree Empty tree (0 nodes) OR Root node and 0 or more non-empty subtrees (child node and its descendents) 10/18/2019

Tree Traversal To traverse any data structure means to visit every node in turn in a systematic manner 10/18/2019

Review: List Traversal List – process sequentially by iteration 2. recursion 10/18/2019

Tree Traversal Pre-order In-order Post-order 10/18/2019

Pre-order Traversal Recursive definition: Visit root before children 1 2 5 9 3 6 11 8 10 7 4 Recursive definition: Visit root before children Algorithm preOrder(v) visit(v) for each child w of v preOrder (w) 10/18/2019

Post-order Traversal Recursive definition: Visit root after children 11 2 10 5 1 4 9 6 7 8 3 Recursive definition: Visit root after children Algorithm postOrder(v) for each child w of v postOrder (w) visit(v) 10/18/2019

Traversal example 7 Pre-order: 7 4 3 5 12 9 Post-order: 3 5 4 9 12 7 4 10/18/2019

Implementing trees List Tree class ListNode Node: data & reference Node: data & references class ListNode {int data; ListNode next; } class TreeNode TreeNode child1, child2, child3; 10/18/2019

Implementing trees Problem of representing a node: How many edges to allow for? e.g., Class TreeNode { int data; TreeNode child1, child2, child3; } 10/18/2019

Implementing trees Problem of representing a node: Three solutions: allow lots of child edge references restrict tree structure to two child edges (binary tree) use first child/next sibling representation 10/18/2019

First child/next sibling Class TreeNode { int data; TreeNode child, sibling; } Problem: Makes path to most nodes longer 10/18/2019