Lecture11: Tree I Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)

Slides:



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

S. Sudarshan Based partly on material from Fawzi Emad & Chau-Wen Tseng
Tree Data Structures &Binary Search Tree 1. Trees Data Structures Tree  Nodes  Each node can have 0 or more children  A node can have at most one parent.
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
Data Structures Lecture 6 Fang Yu Department of Management Information Systems National Chengchi University Fall 2010.
Trees Briana B. Morrison Adapted from Alan Eugenio.
1 Trees most slides taken from Mike Scott, UT Austin.
1 prepared from lecture material © 2004 Goodrich & Tamassia COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material.
CS2420: Lecture 13 Vladimir Kulyukin Computer Science Department Utah State University.
© 2004 Goodrich, Tamassia Trees1 Make Money Fast! Stock Fraud Ponzi Scheme Bank Robbery.
1 Trees. 2 Outline –Tree Structures –Tree Node Level and Path Length –Binary Tree Definition –Binary Tree Nodes –Binary Search Trees.
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
© 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.
1 Trees What is a Tree? Tree terminology Why trees? What is a general tree? Implementing trees Binary trees Binary tree implementation Application of Binary.
Chapter 7: Trees Objectives:
© 2004 Goodrich, Tamassia Trees1 Lecture 04 Trees Topics Trees Binary Trees Binary Search 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.
1 Trees What is a Tree? Tree terminology Why trees? General Trees and their implementation N-ary Trees N-ary Trees implementation Implementing trees Binary.
Marc Smith and Jim Ten Eyck
General Trees. Tree Traversal Algorithms. Binary Trees. 2 CPSC 3200 University of Tennessee at Chattanooga – Summer 2013 © 2010 Goodrich, Tamassia.
Trees CS /02/05 L7: Trees Slide 2 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Definition.
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.
COSC2007 Data Structures II
Trees.
Lecture12: Tree II Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)
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. 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.
Trees 4/23/2017 Trees.
Binary Trees, Binary Search Trees RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
COMP20010: Algorithms and Imperative Programming Lecture 1 Trees.
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. 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.
Trees CS 105. L9: Trees Slide 2 Definition The Tree Data Structure stores objects (nodes) hierarchically nodes have parent-child relationships operations.
1 Binary Trees (7.3) CSE 2011 Winter November 2015.
Trees1 Make Money Fast! Stock Fraud Ponzi Scheme Bank Robbery © 2010 Goodrich, Tamassia.
Data Structures TREES.
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.
CH 7. TREES ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA AND MOUNT (WILEY.
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.
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.
CH 7 : TREE ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA AND MOUNT (WILEY.
1 Trees What is a Tree? Tree terminology Why trees? What is a general tree? Implementing trees Binary trees Binary tree implementation Application of Binary.
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.
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
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 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,
Lecture 1 (UNIT -4) TREE SUNIL KUMAR CIT-UPES.
Trees Make Money Fast! Stock Fraud Ponzi Scheme Bank Robbery
University of Palestine
Bohyung Han CSE, POSTECH
Trees 9/21/2018 9:58 PM Trees this is a tree Trees.
Trees and Binary Trees.
Week nine-ten: Trees Trees.
Trees Palestine Gaza West Bank 48 Stolen Land Trees Trees
CS210- Lecture 9 June 20, 2005 Announcements
NATURE VIEW OF A TREE leaves branches root. NATURE VIEW OF A TREE leaves branches root.
Cs212: Data Structures Lecture 7: Tree_Part1
Presentation transcript:

Lecture11: Tree I Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)

CSED233: Data Structures by Prof. Bohyung Han, Fall 2014 A Hierarchical Structure Unix/Linux file systems 2

CSED233: Data Structures by Prof. Bohyung Han, Fall 2014 Tree Data Structures An abstract model of a hierarchical structure  “2‐dimensional” structure  Easy access (similar to array)  Easy insert and removal (similar to linked list) 3 Computers”R”Us SalesR&DManufacturing LaptopsDesktops US International EuropeAsiaCanada

CSED233: Data Structures by Prof. Bohyung Han, Fall 2014 Tree Data Structures An abstract model of a hierarchical structure  Trees consist of nodes and links denoting parent‐child relation  Special case of graphs without loops  Each element (except root) has a parent and zero or more children. 4 Computers”R”Us SalesR&DManufacturing LaptopsDesktops US International EuropeAsiaCanada

CSED233: Data Structures by Prof. Bohyung Han, Fall 2014 Terminology Root: node without parent Internal node: node with at least one child Leaf: node without children Subtree: tree consisting of a node and its descendants Ancestors of a node: parent, grandparent, grand-grandparent, … Descendant of a node: child, grandchild, grand-grandchild, … Depth (level) of a node: number of ancestors Height of a tree: maximum depth of any node 5 A BDC GH E F IJ K A A,B,C,F E,I,J,K,G,H,D Subtree 3

CSED233: Data Structures by Prof. Bohyung Han, Fall 2014 Tree Abstract Data Type Data structure  Node: data element and link to children  Root: a special node List of methods 6 methoddescription root() Return the tree’s root; error if tree is empty parent(v) Return v’s parent; error if v is a root children(v) Return v’s children (an iterable collection of nodes) isRoot(v) Test whether v is a root isExternal(v) Test whether v is an external node isInternal(v) Test whether v is an internal node isEmpty() Test whether the tree has any nodes or not size() Return the number of nodes in the tree

CSED233: Data Structures by Prof. Bohyung Han, Fall 2014 A Linked Structure for Trees A node is represented by an object storing  Element  Parent node  Sequence of children nodes 7 Element Parent node A list of children A child node

CSED233: Data Structures by Prof. Bohyung Han, Fall 2014 A Linked Structure for Trees 8 B D A CE F  B  ADF  C  E

CSED233: Data Structures by Prof. Bohyung Han, Fall 2014 Binary Tree Definition  A tree in which each node has at most two children  Each child is either the left child or the right child of its parent. 9 Left child Right child

CSED233: Data Structures by Prof. Bohyung Han, Fall 2014 Arithmetic Expression Tree Binary tree associated with an arithmetic expression  Internal nodes: operators  External nodes: operands Example: arithmetic expression tree for the expression: 10  2 a1 3b

CSED233: Data Structures by Prof. Bohyung Han, Fall 2014 Decision Tree Binary tree associated with a decision process  Internal nodes: questions with yes/no answer  External nodes: decisions Example: dining decision 11 Want a fast meal? On a diet? On expense account? SubwayMcDonald’s???????? YesNo YesNoYesNo

CSED233: Data Structures by Prof. Bohyung Han, Fall 2014 A Linked Structure for Binary Trees A node is represented by an object storing  Element  Parent node  Left child node  Right child node 12 Element Parent node Left childRight child

CSED233: Data Structures by Prof. Bohyung Han, Fall 2014 A Linked Structure for Binary Trees 13   B ADC E  B D A CE

CSED233: Data Structures by Prof. Bohyung Han, Fall 2014 Binary Tree Implementation 14 public class Node { int value; // data stored at node Node left; // pointer to left child Node right; // pointer to right child public Node(int i) { value = i; left = null; right = null; } public Node getLeftChild(Node node) { return left; } public Node getRightChild(Node node) { return right; } public void setLeftChild(Node node) { left = node; } public void setRightChild(Node node) { right = node; } }

CSED233: Data Structures by Prof. Bohyung Han, Fall 2014 Binary Tree Implementation 15 public class BinaryTree { Node root; public Tree() { root = null; } // insert an element to the current tree public void insert(int i) {... } // deleted a node from the current tree public Node delete(int i) {... } // find a node containing a particular value public Node find(int i) {... } }

CSED233: Data Structures by Prof. Bohyung Han, Fall 2014 An Array‐Based Representation 16

CSED233: Data Structures by Prof. Bohyung Han, Fall 2014 An Array‐Based Representation A BD EF CJ G H ABDEFCJGH

CSED233: Data Structures by Prof. Bohyung Han, Fall 2014 Tree Balance Perfect binary tree  A binary tree of height h is perfect if every node has exactly two children and all leaf nodes have the same level.  Perfect binary tree is sometimes called full binary tree. 18

CSED233: Data Structures by Prof. Bohyung Han, Fall 2014 Tree Balance Complete binary tree  A binary tree is complete if it is full to level h‐1 and level h is filled from the left with contiguous nodes. 19

CSED233: Data Structures by Prof. Bohyung Han, Fall 2014 Tree Balance Proper binary tree  A binary tree in which each node has exactly zero or two children  Proper binary tree is sometimes called full binary tree. 20

CSED233: Data Structures by Prof. Bohyung Han, Fall 2014 Proper Binary Trees 21

22