Chapter 11.!!!!Trees! 2011 Pearson Addison-Wesley. All rights reserved 11 A-1

Similar documents
Chapter 11.!!!!Trees! 2011 Pearson Addison-Wesley. All rights reserved 11 A-1

Trees 11/15/16. Chapter 11. Terminology. Terminology. Terminology. Terminology. Terminology

Terminology. The ADT Binary Tree. The ADT Binary Search Tree

Tree Terminology. root. Edge. interior node. parent. path. subtree. child. leaf

CS200: Trees. Rosen Ch & 11.3 Prichard Ch. 11. CS200 - Trees

CS200 Midterm 2 Fall 2007

Binary Trees, Binary Search Trees

Trees. Q: Why study trees? A: Many advance ADTs are implemented using tree-based data structures.

Outline. Part 6. Trees (1) Data RepresentaCon. Terminology 3/2/12. Represent hierarchical relationships B C D. Parent node

Trees. (Trees) Data Structures and Programming Spring / 28

CS302 - Data Structures using C++

Chapter 20: Binary Trees

Tree Structures. A hierarchical data structure whose point of entry is the root node

If you took your exam home last time, I will still regrade it if you want.

Programming II (CS300)

BBM 201 Data structures

TREES. Trees - Introduction

Binary Trees

A set of nodes (or vertices) with a single starting point

Trees. CSE 373 Data Structures

Binary Trees Fall 2018 Margaret Reid-Miller

Topic 14. The BinaryTree ADT

CSCI-401 Examlet #5. Name: Class: Date: True/False Indicate whether the sentence or statement is true or false.

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer)

Trees : Part 1. Section 4.1. Theory and Terminology. A Tree? A Tree? Theory and Terminology. Theory and Terminology

March 20/2003 Jayakanth Srinivasan,

tree nonlinear Examples

Data Structures. Trees. By Dr. Mohammad Ali H. Eljinini. M.A. Eljinini, PhD

COMP : Trees. COMP20012 Trees 219

Trees. Truong Tuan Anh CSE-HCMUT

Data Structure Lecture#10: Binary Trees (Chapter 5) U Kang Seoul National University

Trees! Ellen Walker! CPSC 201 Data Structures! Hiram College!

Lecture Topics. Object Structures. Hierarchical Organization. Tree Concepts. Hierarchical Organization. Hierarchical Organization

CS24 Week 8 Lecture 1

Friday Four Square! 4:15PM, Outside Gates

CS200 Final Exam Fall 2007

Data Structures and Algorithms for Engineers

Algorithms and Data Structures

Tree. A path is a connected sequence of edges. A tree topology is acyclic there is no loop.

Trees Chapter 19, 20. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Why Do We Need Trees?

Trees. Tree Structure Binary Tree Tree Traversals

Outline. Preliminaries. Binary Trees Binary Search Trees. What is Tree? Implementation of Trees using C++ Tree traversals and applications

The tree data structure. Trees COL 106. Amit Kumar Shweta Agrawal. Acknowledgement :Many slides are courtesy Douglas Harder, UWaterloo

Complete Binary Trees

Trees. Introduction & Terminology. February 05, 2018 Cinda Heeren / Geoffrey Tien 1

Abstract Data Structures IB Computer Science. Content developed by Dartford Grammar School Computer Science Department

Lec 17 April 8. Topics: binary Trees expression trees. (Chapter 5 of text)

Module 4: Index Structures Lecture 13: Index structure. The Lecture Contains: Index structure. Binary search tree (BST) B-tree. B+-tree.

Tables and Priority Queues!

CMPT 225. Binary Search Trees

Trees. A tree is a directed graph with the property

DATA STRUCTURES AND ALGORITHMS. Hierarchical data structures: AVL tree, Bayer tree, Heap

COSC 2011 Section N. Trees: Terminology and Basic Properties

Uses for Trees About Trees Binary Trees. Trees. Seth Long. January 31, 2010

CSI33 Data Structures

Trees. Trees. CSE 2011 Winter 2007

References and Homework ABSTRACT DATA TYPES; LISTS & TREES. Abstract Data Type (ADT) 9/24/14. ADT example: Set (bunch of different values)

Copyright 1998 by Addison-Wesley Publishing Company 147. Chapter 15. Stacks and Queues

Tables and Priority Queues

CS302 - Data Structures using C++

Chapter Contents. Trees. Tree Concepts. Hierarchical Organization. Hierarchical Organization. Hierarchical Organization.

CSE 230 Intermediate Programming in C and C++ Binary Tree

Binary Trees. BSTs. For example: Jargon: Data Structures & Algorithms. root node. level: internal node. edge.

Tree Travsersals and BST Iterators

Trees. 1 Introduction. 2 Trees. Prof. Stewart Weiss. CSci 235 Software Design and Analysis II Trees

Computer Science 210 Data Structures Siena College Fall Topic Notes: Trees

CSC148 Week 6. Larry Zhang

Trees, Binary Trees, and Binary Search Trees

Trees. Estruturas de Dados / Programação 2 Árvores. Márcio Ribeiro twitter.com/marciomribeiro. Introduc)on. Hierarchical structure

Binary Trees. Height 1

Introduction. for large input, even access time may be prohibitive we need data structures that exhibit times closer to O(log N) binary search tree

Garbage Collection: recycling unused memory

A Binary Search Tree Implementation

Algorithms. Deleting from Red-Black Trees B-Trees

About This Lecture. Trees. Outline. Recursive List Definition slide 1. Recursive Tree Definition. Recursive List Definition slide 2

Bioinformatics Programming. EE, NCKU Tien-Hao Chang (Darby Chang)

csci 210: Data Structures Trees

7.1 Introduction. A (free) tree T is A simple graph such that for every pair of vertices v and w there is a unique path from v to w

INF2220: algorithms and data structures Series 1

CISC 235 Topic 3. General Trees, Binary Trees, Binary Search Trees

Cpt S 122 Data Structures. Data Structures Trees

TREES Lecture 10 CS2110 Spring2014

Also, recursive methods are usually declared private, and require a public non-recursive method to initiate them.

Computational Optimization ISE 407. Lecture 16. Dr. Ted Ralphs

void insert( Type const & ) void push_front( Type const & )

CS 171: Introduction to Computer Science II. Binary Search Trees

Discussion 2C Notes (Week 8, February 25) TA: Brian Choi Section Webpage:

9/29/2016. Chapter 4 Trees. Introduction. Terminology. Terminology. Terminology. Terminology

Tree traversals and binary trees

! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge

Trees. Eric McCreath

Todays Lecture. Assignment 2 deadline: You have 5 Calendar days to complete.

Section 5.5. Left subtree The left subtree of a vertex V on a binary tree is the graph formed by the left child L of V, the descendents

Binary Trees. Examples:

Data Structures and Algorithms

Binary Search Trees Treesort

CS200: Balanced Search Trees

1 Binary trees. 1 Binary search trees. 1 Traversal. 1 Insertion. 1 An empty structure is an empty tree.

Data Structure - Binary Tree 1 -

Transcription:

Chapter 11!!!!Trees! 2011 Pearson Addison-Wesley. All rights reserved 11 A-1 2015-03-25 21:47:41 1/53 Chapter-11.pdf (#4)

Terminology Definition of a general tree! A general tree T is a set of one or more nodes such that T is partitioned into disjoint subsets:! A single node r, the root! Sets that are general trees, called subtrees of r! Definition of a binary tree! A binary tree is a set T of nodes such that either! T is empty, or! T is partitioned into three disjoint subsets:! A single node r, the root! Two possibly empty sets that are binary trees, called left and right subtrees of r! 2011 Pearson Addison-Wesley. All rights reserved 11 A-2 2015-03-25 21:47:41 2/53 Chapter-11.pdf (2/53)

2015-03-25 21:47:41 3/53 Chapter-11.pdf (3/53)

2015-03-25 21:47:42 4/53 Chapter-11.pdf (4/53)

Terminology Figure 11-4 Binary trees that represent algebraic expressions 2011 Pearson Addison-Wesley. All rights reserved 11 A-3 2015-03-25 21:47:42 5/53 Chapter-11.pdf (5/53)

Terminology A binary search tree! A binary tree that has the following properties for each node n! n s value is greater than all values in its left subtree T L! n s value is less than all values in its right subtree T R! Both T L and T R are binary search trees! Figure 11-5 A binary search tree of names 2011 Pearson Addison-Wesley. All rights reserved 11 A-4 2015-03-25 21:47:42 6/53 Chapter-11.pdf (6/53)

2015-03-25 21:47:42 7/53 Chapter-11.pdf (7/53)

2015-03-25 21:47:42 8/53 Chapter-11.pdf (8/53)

Terminology The height of trees! Level of a node n in a tree T! If n is the root of T, it is at level 1! If n is not the root of T, its level is 1 greater than the level of its parent! Height of a tree T defined in terms of the levels of its nodes! If T is empty, its height is 0! If T is not empty, its height is equal to the maximum level of its nodes! 2011 Pearson Addison-Wesley. All rights reserved 11 A-5 2015-03-25 21:47:42 9/53 Chapter-11.pdf (9/53)

Terminology Figure 11-6 Binary trees with the same nodes but different heights 2011 Pearson Addison-Wesley. All rights reserved 11 A-6 2015-03-25 21:47:42 10/53 Chapter-11.pdf (10/53)

Terminology Full, complete, and balanced binary trees! Recursive definition of a full binary tree! If T is empty, T is a full binary tree of height 0! If T is not empty and has height h > 0, T is a full binary tree if its root s subtrees are both full binary trees of height h 1! Figure 11-7 A full binary tree of height 3 2011 Pearson Addison-Wesley. All rights reserved 11 A-7 2015-03-25 21:47:42 11/53 Chapter-11.pdf (11/53)

Terminology Complete binary trees! A binary tree T of height h is complete if! All nodes at level h 2 and above have two children each, and! When a node at level h 1 has children, all nodes to its left at the same level have two children each, and! When a node at level h 1 has one child, it is a left child! Figure 11-8 A complete binary tree 2011 Pearson Addison-Wesley. All rights reserved 11 A-8 2015-03-25 21:47:42 12/53 Chapter-11.pdf (12/53)

Terminology Balanced binary trees! A binary tree is balanced if the height of any node s right subtree differs from the height of the node s left subtree by no more than 1! Full binary trees are complete! Complete binary trees are balanced! 2011 Pearson Addison-Wesley. All rights reserved 11 A-9 2015-03-25 21:47:42 13/53 Chapter-11.pdf (13/53)

Terminology Summary of tree terminology! General tree! A set of one or more nodes, partitioned into a root node and subsets that are general subtrees of the root! Parent of node n! The node directly above node n in the tree! Child of node n! A node directly below node n in the tree! Root! The only node in the tree with no parent! 2011 Pearson Addison-Wesley. All rights reserved 11 A-10 2015-03-25 21:47:42 14/53 Chapter-11.pdf (14/53)

Terminology Summary of tree terminology (Continued)! Leaf! A node with no children! Siblings! Nodes with a common parent! Ancestor of node n! A node on the path from the root to n! Descendant of node n! A node on a path from n to a leaf! Subtree of node n! A tree that consists of a child (if any) of n and the child s descendants! 2011 Pearson Addison-Wesley. All rights reserved 11 A-11 2015-03-25 21:47:43 15/53 Chapter-11.pdf (15/53)

Terminology Summary of tree terminology (Continued)! Height! The number of nodes on the longest path from the root to a leaf! Binary tree! A set of nodes that is either empty or partitioned into a root node and one or two subsets that are binary subtrees of the root! Each node has at most two children, the left child and the right child! Left (right) child of node n! A node directly below and to the left (right) of node n in a binary tree! 2011 Pearson Addison-Wesley. All rights reserved 11 A-12 2015-03-25 21:47:43 16/53 Chapter-11.pdf (16/53)

Terminology Summary of tree terminology (Continued)! Left (right) subtree of node n! In a binary tree, the left (right) child (if any) of node n plus its descendants! Binary search tree! A binary tree where the value in any node n is greater than the value in every node in n s left subtree, but less than the value of every node in n s right subtree! Empty binary tree! A binary tree with no nodes! 2011 Pearson Addison-Wesley. All rights reserved 11 A-13 2015-03-25 21:47:43 17/53 Chapter-11.pdf (17/53)

Terminology Summary of tree terminology (Continued)! Full binary tree! A binary tree of height h with no missing nodes! All leaves are at level h and all other nodes each have two children! Complete binary tree! A binary tree of height h that is full to level h 1 and has level h filled in from left to right! Balanced binary tree! A binary tree in which the left and right subtrees of any node have heights that differ by at most 1! 2011 Pearson Addison-Wesley. All rights reserved 11 A-14 2015-03-25 21:47:43 18/53 Chapter-11.pdf (18/53)

The ADT Binary Tree: Basic Operations of the ADT Binary Tree The operations available for a particular ADT binary tree depend on the type of binary tree being implemented! Basic operations of the ADT binary tree! createbinarytree() createbinarytree(rootitem) makeempty() isempty() getrootitem() throws TreeException 2011 Pearson Addison-Wesley. All rights reserved 11 A-15 2015-03-25 21:47:43 19/53 Chapter-11.pdf (19/53)

General Operations of the ADT Binary Tree General operations of the ADT binary tree! createbinarytree (rootitem, lefttree, righttree) setrootitem(newitem) attachleft(newitem) throws TreeException attachright(newitem) throws TreeException attachleftsubtree(lefttree) throws TreeException attachrightsubtree(righttree) throws TreeException detachleftsubtree() throws TreeException detachrightsubtree() throws TreeException 2011 Pearson Addison-Wesley. All rights reserved 11 A-16 2015-03-25 21:47:43 20/53 Chapter-11.pdf (20/53)

Traversals of a Binary Tree A traversal algorithm for a binary tree visits each node in the tree! Recursive traversal algorithms! Preorder traversal! Inorder traversal! Postorder traversal! Traversal is O(n)! 2011 Pearson Addison-Wesley. All rights reserved 11 A-17 2015-03-25 21:47:43 21/53 Chapter-11.pdf (21/53)

Traversal of a Binary Tree Figure 11-10 Traversals of a binary tree: a) preorder; b) inorder; c) postorder 2011 Pearson Addison-Wesley. All rights reserved 11 A-18 2015-03-25 21:47:43 22/53 Chapter-11.pdf (22/53)

2015-03-25 21:47:43 23/53 Chapter-11.pdf (23/53)

2015-03-25 21:47:43 24/53 Chapter-11.pdf (24/53)

2015-03-25 21:47:43 25/53 Chapter-11.pdf (25/53)

Possible Representations of a Binary Tree An array-based representation! A Java class is used to define a node in the tree! A binary tree is represented by using an array of tree nodes! Each tree node contains a data portion and two indexes (one for each of the node s children)! Requires the creation of a free list which keeps track of available nodes! 2011 Pearson Addison-Wesley. All rights reserved 11 A-19 2015-03-25 21:47:43 26/53 Chapter-11.pdf (26/53)

Possible Representations of a Binary Tree Figure 11-11a a) A binary tree of names Figure 11-11b b) its array-based implementations 2011 Pearson Addison-Wesley. All rights reserved 11 A-20 2015-03-25 21:47:44 27/53 Chapter-11.pdf (27/53)

Possible Representations of a Binary Tree An array-based representation of a complete tree! If the binary tree is complete and remains complete! A memory-efficient array-based implementation can be used! 2011 Pearson Addison-Wesley. All rights reserved 11 A-21 2015-03-25 21:47:44 28/53 Chapter-11.pdf (28/53)

Possible Representations of a Binary Tree Figure 11-12 Figure 11-13 Level-by-level numbering of a complete An array-based implementation of the binary tree complete binary tree in Figure 10-12 2011 Pearson Addison-Wesley. All rights reserved 11 A-22 2015-03-25 21:47:44 29/53 Chapter-11.pdf (29/53)

Possible Representations of a Binary Tree A reference-based representation! Java references can be used to link the nodes in the tree! Figure 11-14 A reference-based implementation of a binary tree 2011 Pearson Addison-Wesley. All rights reserved 11 A-23 2015-03-25 21:47:44 30/53 Chapter-11.pdf (30/53)

A Reference-Based Implementation of the ADT Binary Tree Classes that provide a reference-based implementation for the ADT binary tree! TreeNode Represents a node in a binary tree! TreeException An exception class! BinaryTreeBasis An abstract class of basic tree operation! BinaryTree Provides the general operations of a binary tree! Extends BinaryTreeBasis 2011 Pearson Addison-Wesley. All rights reserved 11 A-24 2015-03-25 21:47:44 31/53 Chapter-11.pdf (31/53)

Tree Traversals Using an Iterator TreeIterator Implements the Java Iterator interface! Provides methods to set the iterator to the type of traversal desired! Uses a queue to maintain the current traversal of the nodes in the tree! Nonrecursive traversal (optional)! An iterative method and an explicit stack can be used to mimic actions at a return from a recursive call to inorder! 2011 Pearson Addison-Wesley. All rights reserved 11 B-25 2015-03-25 21:47:44 32/53 Chapter-11.pdf (32/53)

The ADT Binary Search Tree A deficiency of the ADT binary tree which is corrected by the ADT binary search tree! Searching for a particular item! Each node n in a binary search tree satisfies the following properties! n s value is greater than all values in its left subtree T L! n s value is less than all values in its right subtree T R! Both T L and T R are binary search trees! 2011 Pearson Addison-Wesley. All rights reserved 11 B-26 2015-03-25 21:47:44 33/53 Chapter-11.pdf (33/53)

The ADT Binary Search Tree Record! A group of related items, called fields, that are not necessarily of the same data type! Field! A data element within a record! A data item in a binary search tree has a specially designated search key! A search key is the part of a record that identifies it within a collection of records! KeyedItem class Contains the search key as a data field and a method for accessing the search key! Must be extended by classes for items that are in a binary search tree! 2011 Pearson Addison-Wesley. All rights reserved 11 B-27 2015-03-25 21:47:44 34/53 Chapter-11.pdf (34/53)

The ADT Binary Search Tree Operations of the ADT binary search tree! Insert a new item into a binary search tree! Delete the item with a given search key from a binary search tree! Retrieve the item with a given search key from a binary search tree! Traverse the items in a binary search tree in preorder, inorder, or postorder! Figure 11-19 A binary search tree 2011 Pearson Addison-Wesley. All rights reserved 11 B-28 2015-03-25 21:47:44 35/53 Chapter-11.pdf (35/53)

Algorithms for the Operations of the ADT Binary Search Tree Since the binary search tree is recursive in nature, it is natural to formulate recursive algorithms for its operations! A search algorithm! search(bst, searchkey) Searches the binary search tree bst for the item whose search key is searchkey! 2011 Pearson Addison-Wesley. All rights reserved 11 B-29 2015-03-25 21:47:44 36/53 Chapter-11.pdf (36/53)

Algorithms for the Operations of the ADT Binary Search Tree: Insertion insertitem(treenode, newitem) Inserts newitem into the binary search tree of which treenode is the root! Figure 11-23a and 11-23b a) Insertion into an empty tree; b) search terminates at a leaf 2011 Pearson Addison-Wesley. All rights reserved 11 B-30 2015-03-25 21:47:44 37/53 Chapter-11.pdf (37/53)

Algorithms for the Operations of the ADT Binary Search Tree: Insertion Figure 11-23c c) insertion at a leaf 2011 Pearson Addison-Wesley. All rights reserved 11 B-31 2015-03-25 21:47:45 38/53 Chapter-11.pdf (38/53)

Algorithms for the Operations of the ADT Binary Search Tree: Deletion Steps for deletion! Use the search algorithm to locate the item with the specified key! If the item is found, remove the item from the tree! Three possible cases for node N containing the item to be deleted! N is a leaf! N has only one child! N has two children! 2011 Pearson Addison-Wesley. All rights reserved 11 B-32 2015-03-25 21:47:45 39/53 Chapter-11.pdf (39/53)

Algorithms for the Operations of the ADT Binary Search Tree: Deletion Strategies for deleting node N! If N is a leaf! Set the reference in N s parent to null If N has only one child! Let N s parent adopt N s child! If N has two children! Locate another node M that is easier to remove from the tree than the node N! Copy the item that is in M to N! Remove the node M from the tree! 2011 Pearson Addison-Wesley. All rights reserved 11 B-33 2015-03-25 21:47:45 40/53 Chapter-11.pdf (40/53)

Algorithms for the Operations of the ADT Binary Search Tree: Retrieval Retrieval operation can be implemented by refining the search algorithm! Return the item with the desired search key if it exists! Otherwise, return a null reference! 2011 Pearson Addison-Wesley. All rights reserved 11 B-34 2015-03-25 21:47:45 41/53 Chapter-11.pdf (41/53)

Algorithms for the Operations of the ADT Binary Search Tree: Traversal Traversals for a binary search tree are the same as the traversals for a binary tree! Theorem 11-1!!The inorder traversal of a binary search tree T will visit its nodes in sorted search-key order! 2011 Pearson Addison-Wesley. All rights reserved 11 B-35 2015-03-25 21:47:45 42/53 Chapter-11.pdf (42/53)

A Reference-Based Implementation of the ADT Binary Search Tree BinarySearchTree Extends BinaryTreeBasis Inherits the following from BinaryTreeBasis isempty() makeempty() getrootitem() The use of the constructors! TreeIterator Can be used with BinarySearchTree 2011 Pearson Addison-Wesley. All rights reserved 11 B-36 2015-03-25 21:47:45 43/53 Chapter-11.pdf (43/53)

The Efficiency of Binary Search Tree Operations The maximum number of comparisons for a retrieval, insertion, or deletion is the height of the tree! The maximum and minimum heights of a binary search tree! n is the maximum height of a binary tree with n nodes! Figure 11-30 A maximum-height binary tree with seven nodes 2011 Pearson Addison-Wesley. All rights reserved 11 B-37 2015-03-25 21:47:45 44/53 Chapter-11.pdf (44/53)

The Efficiency of Binary Search Tree Operations Theorem 11-2!!A full binary tree of height h 0 has 2 h 1 nodes! Theorem 11-3!!The maximum number of nodes that a binary tree of height h can have is 2 h 1! Figure 11-32 Counting the nodes in a full binary tree of height h 2011 Pearson Addison-Wesley. All rights reserved 11 B-38 2015-03-25 21:47:45 45/53 Chapter-11.pdf (45/53)

The Efficiency of Binary Search Tree Operations Theorem 11-4!!The minimum height of a binary tree with n nodes is!log 2 (n+1)"! The height of a particular binary search tree depends on the order in which insertion and deletion operations are performed! Figure 11-34 The order of the retrieval, insertion, deletion, and traversal operations for the reference-based implementation of the ADT binary search tree 2011 Pearson Addison-Wesley. All rights reserved 11 B-39 2015-03-25 21:47:45 46/53 Chapter-11.pdf (46/53)

Treesort Treesort! Uses the ADT binary search tree to sort an array of records into search-key order! Efficiency! Average case: O(n * log n)! Worst case: O(n 2 )! 2011 Pearson Addison-Wesley. All rights reserved 11 B-40 2015-03-25 21:47:45 47/53 Chapter-11.pdf (47/53)

Saving a Binary Search Tree in a File Two algorithms for saving and restoring a binary search tree! Saving a binary search tree and then restoring it to its original shape! Uses preorder traversal to save the tree to a file! Saving a binary tree and then restoring it to a balanced shape! Uses inorder traversal to save the tree to a file! Can be accomplished if! The data is sorted! The number of nodes in the tree is known! 2011 Pearson Addison-Wesley. All rights reserved 11 B-41 2015-03-25 21:47:46 48/53 Chapter-11.pdf (48/53)

The JCF Binary Search Algorithm JCF has two binary search methods! Based on the natural ordering of elements:! static <T> int! binarysearch (List<? extends Comparable<? super T>> list, T key)! Based on a specified Comparator:! static <T> int binarysearch (List<? extends T> list, T key,!!!!!!comparator<? super T> c)!! 2011 Pearson Addison-Wesley. All rights reserved 5 B-42 2015-03-25 21:47:46 49/53 Chapter-11.pdf (49/53)

General Trees An n-ary tree! A generalization of a binary tree whose nodes each can have no more than n children! Figure 11-38 A general tree Figure 11-41 An implementation of the n-ary tree in Figure 11-38 2011 Pearson Addison-Wesley. All rights reserved 11 B-43 2015-03-25 21:47:46 50/53 Chapter-11.pdf (50/53)

Summary Binary trees provide a hierarchical organization of data! Implementation of binary trees! The implementation of a binary tree is usually referenced-based! If the binary tree is complete, an efficient array-based implementation is possible! Traversing a tree is a useful operation! The binary search tree allows you to use a binary search-like algorithm to search for an item with a specified value! 2011 Pearson Addison-Wesley. All rights reserved 11 B-44 2015-03-25 21:47:46 51/53 Chapter-11.pdf (51/53)

Summary Binary search trees come in many shapes! The height of a binary search tree with n nodes can range from a minimum of!log 2 (n + 1)" to a maximum of n! The shape of a binary search tree determines the efficiency of its operations! An inorder traversal of a binary search tree visits the tree s nodes in sorted search-key order! The treesort algorithm efficiently sorts an array by using the binary search tree s insertion and traversal operations! 2011 Pearson Addison-Wesley. All rights reserved 11 B-45 2015-03-25 21:47:46 52/53 Chapter-11.pdf (52/53)

Summary Saving a binary search tree to a file! To restore the tree as a binary search tree of minimum height! Perform inorder traversal while saving the tree to a file! To restore the tree to its original form! Perform preorder traversal while saving the tree to a file! 2011 Pearson Addison-Wesley. All rights reserved 11 B-46 2015-03-25 21:47:46 53/53 Chapter-11.pdf (53/53)