Tree Implementations Chapter 24 Copyright ©2012 by Pearson Education, Inc. All rights reserved.

Slides:



Advertisements
Similar presentations
Trees 2 and Doubly Linked Lists As you arrive: Please snarf today’s code.
Advertisements

An Introduction to Sorting Chapter 8 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
A Bag Implementation that Links Data Chapter 3 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 26 Binary Search Trees.
© 2006 Pearson Addison-Wesley. All rights reserved11 A-1 Chapter 11 Trees.
© 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.
Chapter 12 Trees. Copyright © 2005 Pearson Addison-Wesley. All rights reserved Chapter Objectives Define trees as data structures Define the terms.
Trees Chapter 23 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
A Binary Search Tree Implementation Chapter 25 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Graph Implementations Chapter 29 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Graphs Chapter 28 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Searching Chapter 18 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Marc Smith and Jim Ten Eyck
A Binary Search Tree Implementation Chapter 27 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Chapter 18 - basic definitions - binary trees - tree traversals Intro. to Trees 1CSCI 3333 Data Structures.
Trees & Graphs Chapter 25 Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X.
Trees Chapter 15 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 10: Trees Data Abstraction & Problem Solving with C++
Balanced Search Trees Chapter 27 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
© 2011 Pearson Addison-Wesley. All rights reserved 11 B-1 Chapter 11 (continued) Trees.
Chapter 19 Implementing Trees and Priority Queues Fundamentals of Java.
Chapter 19 Implementing Trees and Priority Queues Fundamentals of Java.
Tree Implementations Chapter 16 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Chapter 11 B Trees. © 2004 Pearson Addison-Wesley. All rights reserved 11 B-2 The ADT Binary Search Tree A deficiency of the ADT binary tree which is.
Computer Science 112 Fundamentals of Programming II Introduction to Trees.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. 1 Chapter 19 Binary Search Trees.
Chapter 12 Abstract Data Type. Understand the concept of an abstract data type (ADT). Understand the concept of a linear list as well as its operations.
A Heap Implementation Chapter 26 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Trees Chapter 23 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Iterators (short version) Chapter 15 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
© 2006 Pearson Addison-Wesley. All rights reserved11 A-1 Chapter 11 Trees.
Copyright © 2012 Pearson Education, Inc. Chapter 20: Binary Trees.
Tree Implementations Chapter 24 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with Java,
Tree Implementations Chapter Chapter Contents The Nodes in a Binary Tree An Interface for a Node An implementation of BinaryNode An Implementation.
Data Abstraction and Problem Solving with JAVA Walls and Mirrors Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley Data Abstraction and Problem.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 20: Binary Trees.
Copyright © 2012 Pearson Education, Inc. Chapter 10 Advanced Topics.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 20: Binary Trees.
Planning & System installation
Chapter 10 Trees © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
Trees Chapter 15.
Trees Chapter 11 (continued)
Fundamentals of Programming II Introduction to Trees
Planning & System installation
Trees Chapter 11 (continued)
Planning & System installation
Chapter 11 Trees © 2011 Pearson Addison-Wesley. All rights reserved.
An Introduction to Sorting
A Bag Implementation that Links Data
Chapter 16 Tree Implementations
A Binary Search Tree Implementation
Tree Implementations (plus briefing about Iterators)
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Trees.
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Slides by Steve Armstrong LeTourneau University Longview, TX
Chapter 16 Tree Implementations
List Implementations that Use Arrays
A List Implementation That Links Data
Copyright ©2012 by Pearson Education, Inc. All rights reserved
General Trees & Binary Trees
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Binary Search Trees Chapter 7 Objectives
Chapter 11 Trees © 2011 Pearson Addison-Wesley. All rights reserved.
A Binary Search Tree Implementation
A List Implementation That Links Data
List Implementations that Use Arrays
Presentation transcript:

Tree Implementations Chapter 24 Copyright ©2012 by Pearson Education, Inc. All rights reserved

Contents The Nodes in a Binary Tree  An Interface for a Node  An Implementation of BinaryNode An Implementation of the ADT Binary Tree  Creating a Basic Binary Tree  The Method privateSetTree  Accessor and Mutator Methods  Computing the Height and Counting Nodes  Traversals Copyright ©2012 by Pearson Education, Inc. All rights reserved

Contents An Implementation of an Expression Tree  General Trees  A Node for a General Tree  Using a Binary Tree to Represent a General Tree Copyright ©2012 by Pearson Education, Inc. All rights reserved

Objectives Describe necessary operations on node within binary tree Implement class of nodes for binary tree Implement class of binary trees Implement an expression tree by extending class of binary trees Describe necessary operations on a node within general tree Use binary tree to represent general tree Copyright ©2012 by Pearson Education, Inc. All rights reserved

Figure 24-1 A node in a binary tree Copyright ©2012 by Pearson Education, Inc. All rights reserved

An Interface for a Node Note code for node interface, Listing 24-1Listing 24-1 An implementation of BinaryNode, Listing 24-2 Listing 24-2 Creating a basic binary tree  First draft of the class, Listing 24-3Listing 24-3 Copyright ©2012 by Pearson Education, Inc. All rights reserved Note: Code listing files must be in same folder as PowerPoint files for links to work Note: Code listing files must be in same folder as PowerPoint files for links to work

Figure 24-2 The binary tree treeA shares nodes with treeB and treeC Copyright ©2012 by Pearson Education, Inc. All rights reserved

Figure 24-3 treeA has identical subtrees Copyright ©2012 by Pearson Education, Inc. All rights reserved

Traversing Recursively Inorder traversal  Public method for user, calls private method Copyright ©2012 by Pearson Education, Inc. All rights reserved

Figure 24-4 A binary tree Copyright ©2012 by Pearson Education, Inc. All rights reserved

Traversals with An Iterator Iterator traversal provides more flexibility Class BinaryTree must implement methods in interface TreeIteratorInterface Possible to use a stack to do inorder traversal  Note example, Listing 24-AListing 24-A Private class InorderIterator, Listing 24-4Listing 24-4 Copyright ©2012 by Pearson Education, Inc. All rights reserved

Figure 24-5 Using a stack to perform an inorder traversal of a binary tree Copyright ©2012 by Pearson Education, Inc. All rights reserved

Figure 24-6 Using a stack to traverse a binary tree in (a) preorder; Copyright ©2012 by Pearson Education, Inc. All rights reserved

Figure 24-6 Using a stack to traverse a binary tree in (b) postorder; Copyright ©2012 by Pearson Education, Inc. All rights reserved

Figure 24-7 Using a queue to traverse a binary tree in level order Copyright ©2012 by Pearson Education, Inc. All rights reserved

Implementation of an Expression Tree Note interface, Listing 24-5Listing 24-5 Derive from BinaryTree, Listing 24-6Listing 24-6 Copyright ©2012 by Pearson Education, Inc. All rights reserved

Node for a General Tree Copyright ©2012 by Pearson Education, Inc. All rights reserved Figure 24-8 A node for a general tree

Node for a General Tree Interface, Listing 24-7Listing 24-7 Copyright ©2012 by Pearson Education, Inc. All rights reserved

Using a Binary Tree to Represent a General Tree Copyright ©2012 by Pearson Education, Inc. All rights reserved Figure 24-9 (a) A general tree; (b) an equivalent binary tree;

Figure 24-9 (c) a more conventional view of the same binary tree Copyright ©2012 by Pearson Education, Inc. All rights reserved

End Chapter 24 Copyright ©2012 by Pearson Education, Inc. All rights reserved