Razdan CST230http://dcst2.east.asu.edu/~razdan/cst230/ Razdan with contribution from others 1 Chapter 9 Trees Anshuman Razdan Div of Computing Studies.

Slides:



Advertisements
Similar presentations
A.A DA1: Binary Tree1 Binary Tree. A.A DA1: Binary Tree2 Implementazione usa Tree LinkedBinaryTree BinaryTree NodePositionList PositionList.
Advertisements

Chapter 7. Binary Search Trees
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.
Computer Science C++ High School Level By Guillermo Moreno.
trees1 Binary Trees trees2 Basic terminology nodesFinite set of nodes (may be empty -- 0 nodes), which contain data rootFirst node in tree is called.
CS 206 Introduction to Computer Science II 09 / 22 / 2008 Instructor: Michael Eckmann.
Binary Tree B G E D I H F c A Binary tree
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. Lecture 5: Trees Data Structures.
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.
Introduction to Data Structure, Fall 2006 Slide- 1 California State University, Fresno Introduction to Data Structure Chapter 10 Ming Li Department of.
© 2006 Pearson Addison-Wesley. All rights reserved11 A-1 Chapter 11 Trees.
CS 206 Introduction to Computer Science II 02 / 11 / 2009 Instructor: Michael Eckmann.
CST 230 Razdan et alhttp://dcst2.east.asu.edu/~razdan/cst230/ Razdan with contribution from others 1 Tree Traversals Pre-order traversal –process root.
Chapter 9 contd. Binary Search Trees Anshuman Razdan Div of Computing Studies
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.
Joseph Lindo Trees Sir Joseph Lindo University of the Cordilleras.
CS 206 Introduction to Computer Science II 09 / 30 / 2009 Instructor: Michael Eckmann.
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.
Data Structures Arrays both single and multiple dimensions Stacks Queues Trees Linked Lists.
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.
UNCA CSCI September, 2001 These notes were prepared by the text’s author Clifford A. Shaffer Department of Computer Science Virginia Tech Copyright.
1 Trees Tree nomenclature Implementation strategies Traversals –Depth-first –Breadth-first Implementing binary search trees.
Trees Chapter 15 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
CS Data Structures Chapter 5 Trees. Chapter 5 Trees: Outline  Introduction  Representation Of Trees  Binary Trees  Binary Tree Traversals 
Chapter 19 Implementing Trees and Priority Queues Fundamentals of Java.
CISC220 Fall 2009 James Atlas Lecture 13: Trees. Skip Lists.
CMSC 341 Introduction to Trees. 8/3/2007 UMBC CMSC 341 TreeIntro 2 Tree ADT Tree definition  A tree is a set of nodes which may be empty  If not empty,
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.
Topic 17 Introduction to 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.
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 4. Trees.
CS-2852 Data Structures LECTURE 11 Andrew J. Wozniewicz Image copyright © 2010 andyjphoto.com.
Computer Science 112 Fundamentals of Programming II Introduction to Trees.
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.
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.
TREES K. Birman’s and G. Bebis’s Slides. Tree Overview 2  Tree: recursive data structure (similar to list)  Each cell may have zero or more successors.
© 2006 Pearson Addison-Wesley. All rights reserved11 A-1 Chapter 11 Trees.
Binary Trees. 2 Parts of a binary tree A binary tree is composed of zero or more nodes In Java, a reference to a binary tree may be null Each node contains:
Foundation of Computing Systems Lecture 4 Trees: Part I.
Chapter 10 Trees © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
1 CMSC 341 Introduction to Trees Textbook sections:
Trees A non-linear implementation for collection classes.
(c) University of Washington20-1 CSC 143 Java Trees.
1 Trees. 2 Trees Trees. Binary Trees Tree Traversal.
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.
Recursive Objects (Part 4)
Chapter 11 Trees © 2011 Pearson Addison-Wesley. All rights reserved.
Tree.
Section 8.1 Trees.
Trees What is a Tree? Tree terminology Why trees?
CS223 Advanced Data Structures and Algorithms
Binary Trees.
CMPT 225 Binary Search Trees.
Abstract Data Structures
Trees.
Binary Trees.
Topic 18 Binary Trees "A tree may grow a thousand feet tall, but its leaves will return to its roots." -Chinese Proverb.
Trees Definitions Implementation Traversals K-ary Trees
CSE 373, Copyright S. Tanimoto, 2002 Binary Trees -
Lecture 36 Section 12.2 Mon, Apr 23, 2007
Non-Linear Structures
CSE 373, Copyright S. Tanimoto, 2001 Binary Trees -
CSC 143 Java Trees.
Chapter 20: Binary Trees.
Binary Trees.
Presentation transcript:

Razdan CST230http://dcst2.east.asu.edu/~razdan/cst230/ Razdan with contribution from others 1 Chapter 9 Trees Anshuman Razdan Div of Computing Studies

Razdan CST2302 Tree a “non-linear” data structure Example: family “tree” tree is made up of nodes and edges Trees can be rooted (i.e., have a root node) trees have branches and leaves

Razdan CST2303 Binary Trees A binary tree is a finite (possibly emtpy) set of nodes. If the tree is not empty: –there is one special node, called the root –each node has a left child and right child –each node except the root has exactly one parent (the root has no parent)

Razdan CST2304 Vocabulary Parent Sibling Ancestor Descendant Subtree Left and Right subtrees of a Node Depth of a node leaf Depth of a tree Full Binary tree Complete Binary tree

Razdan CST2305 Tree Representations Two general methods for representing trees: –Arrays – Parent [(i-1)/2], LC[2i+1], RC[2i+2] –linked structure A complete binary tree can be represented using an array. Linked structure for binary trees uses A Node that contains data and two references: class BTNode{ private Object data; private BTNode left; private BTNode right;... }

Razdan CST2306 Example Binary Tree methods iterate boolean isEmpty() boolean equals() Object clone() merge( Object, BinaryTree, BinaryTree ) boolean contains( Object ) void remove( Object ) int size()

Razdan CST2307 BTNode does most of the work BTNode( Object, BTNode, BTNode ) getData, getLeft, getRight setData, setLeft, setRight isLeaf() clone() equals() subTreeContains( Object ) subTreeSize()

Razdan CST2308 Traversals Pre-order traversal –process root –pre-order traverse left subtree –pre-order traverse right subtree

Razdan CST2309 Traversals cont... In-order Traversal –in-order traverse left subtree –process root –in-order traverse right subtree

Razdan CST23010 Traversals cont... Post-order Traversal –post-order traverse left subtree –post-order traverse right subtree –process root