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

Size: px
Start display at page:

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

Transcription

1 Object Structures Trees CISH 4020 Tom Blough Lecture Topics Tree Concepts Traversals of a Tree Java Interfaces for Trees Examples of Binary Trees Examples of General Trees The Nodes in a Binary TreeinaryNode An Implementation of the ADT Binary Tree An Implementation of an Expression Tree General Trees Getting Started with Binary Search Trees Searching and Retrieving Traversing, Adding, and Removing Entries Efficiency of Operations Implementation of the ADT Dictionary Trees 2 Tree Concepts Hierarchical Organization Previous data organizations place data in linear order Some data organizations require categorizing data into groups, subgroups This is hierarchical classification Data items appear at various levels within the organization Example: File directories Trees 3 Trees 4 Hierarchical Organization Hierarchical Organization Example: A university's organization Example: Family trees Trees 5 Trees 6

2 Hierarchical Organization Tree Terminology Example: Family trees A tree is A set of nodes Connected by edges The edges indicate relationships among nodes Nodes arranged in levels Indicate the nodes' hierarchy Top level is a single node called the root Trees 7 Trees 8 Tree Terminology Tree Terminology Nodes at a given level are children of nodes of previous level Node with children is the parent node of those children Nodes with same parent are siblings Node with no children is a leaf node The only node with no parent is the root node All others have one parent each Trees 9 Trees 10 Tree Terminology Binary Trees Empty trees? Some authors specify a general tree must have at least the root node This text will allow all trees to be empty A node is reached from the root by a path The length of the path is the number of edges that compose it The height of a tree is the number of levels in the tree The subtree of a node is a tree rooted at a child of that node Each node has at most two children Trees 11 Trees 12

3 Binary Trees Binary Trees A binary tree is either empty or has the following form Where T left and T right are binary trees Every nonleaf in a full binary tree has exactly two children A complete binary tree is full to its nextto-last level Leaves on last level filled from left to right The height of a binary tree with n nodes that is either complete or full is log 2 (n + 1) Trees 13 Trees 14 Binary Trees The number of nodes in a full binary tree as a function of the tree's height. Traversals of a Tree Visiting a node Processing the data within a node This is the action performed on each node during traversal of a tree A traversal can pass through a node without visiting it at that moment For a binary tree Visit the root Visit all nodes in the root's left subtree Visit all nodes in the root's right subtree Trees 15 Trees 16 Traversals of a Tree Traversals of a Tree Preorder traversal: visit root before the subtrees Inorder traversal: visit root between visiting the subtrees Trees 17 Trees 18

4 Traversals of a Tree Traversals of a Tree Postorder traversal: visit root after visiting the subtrees Level-order traversal: begin at the root, visit nodes one level at a time These are examples of a depth-first traversal. This is an example of a breadth-first traversal. Trees 19 Trees 20 Traversals of a General Tree A general tree has traversals that are in Level order Preorder Postorder Inorder traversal not well defined for a general tree Traversals of a General Tree Trees 21 Trees 22 Java Interfaces for Trees Java Interfaces for Trees An interface that specifies operations common to all trees public interface TreeInterface { public Object getrootdata(); public int getheight(); public int getnumberofnodes(); public boolean isempty(); public void clear(); } // end TreeInterface Interface for iterators for various traversals import java.util.iterator; public interface TreeIteratorInterface { public Iterator getpreorderiterator(); public Iterator getpostorderiterator(); public Iterator getinorderiterator(); public Iterator getlevelorderiterator(); } // end TreeIteratorInterface Trees 23 Trees 24

5 Java Interfaces for Trees Interface for a class of binary trees public interface BinaryTreeInterface extends TreeInterface, TreeIteratorInterface { /** Sets an existing binary tree to a new one-node tree. rootdata a data object in the tree s root */ public void settree(object rootdata); /** Sets an existing binary tree to a new binary tree. rootdata a data object in the tree s root lefttree the left subtree of the new tree righttree the right subtree of the new tree */ public void settree(object rootdata, BinaryTreeInterface lefttree, BinaryTreeInterface righttree); } // end BinaryTreeInterface Trees 25 Java Interfaces for Trees A binary tree whose nodes contain one-letter strings. Trees 26 Examples of Binary Trees Examples of Binary Trees Expression Trees Algorithm for evaluating an expression tree in postorder traversal Algorithm evaluate(expressiontree) if (expressiontree is empty) return 0 else { firstoperand = evaluate(left subtree of expressiontree) secondoperand = evaluate(right subtree of expressiontree) operator = the root of expressiontree return the result of the operation operator and its operands firstoperand and secondoperand } Trees 27 Trees 28 Decision Trees A decision tree can be the basis of an expert system Helps users solve problems, make decisions Decision Trees A possible Java interface for a binary decision tree. public interface DecisionTreeInterface extends BinaryTreeInterface { /** Task: Gets the data in the current node. the data object in the current node */ public Object getcurrentdata(); /** Task: Determines whether current node contains an answer. true if the current node is a leaf */ public boolean isanswer(); /** Task: Moves the current node to the left (right) child */ public void advancetono(); public void advancetoyes(); /** Task: Sets the current node to the root of the tree.*/ public void reset(); } // end DecisionTreeInterface Trees 29 Trees 30

6 Decision Trees Decision Trees An initial decision tree for a guessing game. The decision tree for a guessing game after acquiring another fact. Trees 31 Trees 32 Binary Search Trees A search tree organizes its data so that a search is more efficient Binary search tree Nodes contain Comparable objects A node's data is greater than the data in the node's left subtree A node's data is less than the data in the node's right subtree Binary Search Trees Trees 33 Trees 34 Binary Search Trees Binary Search Trees An algorithm for searching a binary search tree Two binary search trees containing the same names as the previous tree Algorithm bstsearch(binarysearchtree, desiredobject) // Searches a binary search tree for a given object. // Returns true if the object is found. if (binarysearchtree is empty) return false else if (desiredobject == object in the root of binarysearchtree) return true else if (desiredobject < object in the root of binarysearchtree) return bstsearch(left subtree of binarysearchtree, desiredobject) else return bstsearch(right subtree of binarysearchtree, desiredobject) Trees 35 Trees 36

7 Heaps A complete binary tree Nodes contain Comparable objects Each node contains no smaller (or no larger) than objects in its descendants Maxheap Object in a node is its descendant objects Minheap Object in a node is descendant objects Heaps (a) A maxheap and (b) a minheap that contain the same values Trees 37 Trees 38 Examples of General Trees Examples of General Trees A parse tree for the algebraic expression a * (b + c) Trees 39 A portion of a game tree for tic-tac-toe Trees 40 Nodes in a Binary Tree Interface for a Node Interface for class of nodes suitable for a binary tree public interface BinaryNodeInterface { public Object getdata(); public void setdata(object newdata); public BinaryNodeInterface getleftchild(); public BinaryNodeInterface getrightchild(); public void setleftchild(binarynodeinterface leftchild); public void setrightchild(binarynodeinterface rightchild); public boolean hasleftchild(); public boolean hasrightchild(); public boolean isleaf(); } // end BinaryNodeInterface Trees 41 Trees 42

8 Implementation of BinaryNode Usually the class that represents a node in a tree is a detail hidden from the client It is placed within a package Makes it available Available to all classes involved in implementation of a tree An Implementation of the ADT Binary Tree Recall interface for class of binary trees from previous chapter In that interface TreeInterface specifies basic operations common to all trees TreeInteratorInterface specifies operations for tree traversal Note full implementation of BinaryTree, section 25.4 in text. Trees 43 Trees 44 The Method privatesettree Problem: previous implementation of privatesettree not sufficient Given: treea.settree (a, treeb, treec); Now treea shares nodes with treeb, treec Changes to treeb also affect treea (Fig. 25-2) The Method privatesettree Possible solution HaveprivatSetTree copy the nodes in TreeB and TreeC Now treea is separate and distinct from treeb and treec Changes to either treeb or treec do NOT affect treea Note that copying nodes is expensive Other solutions are considered Trees 45 Trees 46 The Method privatesettree Another possible solution for treea.settree( a, treeb, treec); HaveprivateSetTree first link the root node of treea to root nodes of treeb, treec (Fig. 25-3) Then set treeb.root, treec.root to null fig 25-3 here This still has some problems The Method privatesettree Real solution should do the following: 1. Create root node r for containing the data 2. If left subtree exists, not empty Attach root node to r as left child 3. If right subtree exists, not empty, distinct from left subtree Attach root node r as right child If right, left subtrees are the same, attach copy of right subtree to r instead 4. If left (right) subtree exists, different from the invoking tree object Set its data field root to null Trees 47 Trees 48

9 Accessor, Mutator Methods Methods implemented getrootdata() isempty() clear() setrootdata (Object rootdata) setrootnode (BinaryNode rootnode) getrootnode() Computing Height, Counting Nodes Within BinaryTree getheight() getnumberofnodes() Within BinaryNode getheight() getheight(binarynode node) getnumberofnodes() Trees 49 Trees 50 Traversals Make recursive method private Call from public method with no parameters Traversals public void inordertraverse() { inordertraverse(root); } private void inordertraverse(binarynode node) { if (node!= null) { inordertraverse((binarynode)node.getleftchild()); System.out.println(node.getData()); inordertraverse((binarynode)node.getrightchild()); } // end if } // end inordertraverse Trees 51 Trees 52 Traversals Traversals Using a stack to perform an inorder traversal of the previous binary tree. Using a stack to traverse the previous binary tree in preorder Trees 53 Trees 54

10 Traversals Traversals Using a queue to traverse the previous binary tree in level order. Using a stack to traverse the previous binary tree in postorder Trees 55 Trees 56 Implementation of an Expression Tree Defining an interface for an expression tree Extend the interface for a binary tree Add a declaration for the method evaluate public interface ExpressionTreeInterface extends BinaryTreeInterface { /** Task: Computes the value of the expression in the tree. the value of the expression */ public double evaluate(); } // end ExpressionTreeInterface General Trees A node for a general tree. Trees 57 Trees 58 Using a Binary Tree to Represent a General Tree Using a Binary Tree to Represent a General Tree An equivalent binary tree; Trees 59 Trees 60

11 Using a Binary Tree to Represent a General Tree Traversals Traversals of previous general tree in (a) Preorder: A B E F C G H I D J Postorder: E F B G H I C J D A Level order: A B C D E F G H I J Traversals of previous binary tree in (c) Preorder: A B E F C G H I D J Postorder: F E I H G J D C B A Level order: A B E C F G D H J I Inorder: E F B G H I C J D A A more conventional view Trees of the same binary tree. 61 Trees 62 Getting Started with Binary Search Trees Getting Started A binary search tree is a binary tree Nodes contain Comparable objects For each node in the tree The data in a node is greater than the data in the node's left subtree The data in a node is less than the data in the node's right subtree A binary search tree of names. Trees 63 Trees 64 An Interface for the Binary Search Tree An Interface for the Binary Search Tree import java.util.iterator; public interface SearchTreeInterface extends TreeInterface { public boolean contains(comparable entry); public Comparable getentry(comparable entry); public Comparable add(comparable newentry); public Comparable remove(comparable entry); public Iterator getinorderiterator(); } // end SearchTreeInterface Adding an entry that matches an entry already in a binary tree continued Trees 65 Trees 66

12 An Interface for the Binary Search Tree Duplicate Entries If duplicates are allowed, place the duplicate in the entry's right subtree. Adding an entry that matches an entry already in a binary tree. Trees 67 Trees 68 Beginning the Class Definition import java.util.iterator; public class BinarySearchTree extends BinaryTree implements SearchTreeInterface { public BinarySearchTree() { super(); } // end default constructor public BinarySearchTree(Comparable rootentry) { super(); setrootnode(new BinaryNode(rootEntry)); } // end constructor... Note that it is serializable because its base class BinaryTree is serializable. Trees 69 Searching and Retrieving Like performing a binary search of an array For a binary array Search one of two halves of the array For the binary search tree You search one of two subtrees of the binary search tree Trees 70 Searching and Retrieving Traversing The search algorithm Algorithm bstsearch(binarysearchtree, desiredobject) // Searches a binary search tree for a given object. // Returns true if the object is found. if (binarysearchtree is empty) return false else if (desiredobject == object in the root of binarysearchtree) return true else if (desiredobject < object in the root of binarysearchtree) return bstsearch(left subtree of binarysearchtree, desiredobject) else return bstsearch(right subtree of binarysearchtree, desiredobject) The SearchTreeInterface provides the method getinorderiterator Returns an inorder iterator Our class is a subclass of BinaryTree It inherits getinorderiterator This iterator traverses entries in ascending order Uses the entries' method compareto Trees 71 Trees 72

13 Adding an Entry Adding an Entry Recursively (a) A binary search tree; (b) the same tree after adding Chad. Trees 73 Recursively adding Chad to smaller subtrees of a binary search tree continued Trees 74 Adding an Entry Recursively Adding an Entry Recursively Recursively adding Chad to smaller subtrees of a binary search tree. The method addnode copies its argument (null) to its local parameter rootnode; (b) rootnode references a new node that contains Chad Trees 75 Trees 76 Adding an Entry Recursively After adding a node to the subtree passed to it, addnode returns a reference to the subtree so it can be attached to the rest of the original tree. Trees 77 Removing an Entry The remove method must receive an entry to be matched in the tree If found, it is removed Otherwise the method returns null Three cases The node has no children, it is a leaf (simplest case) The node has one child The node has two children Trees 78

14 Removing an Entry, Node a Leaf Removing an Entry, Node Has One Child (a) Two possible configurations of leaf node N; (b) the resulting two possible configurations after removing node N. Trees 79 (a) Four possible configurations of node N with one child; (b) resulting two possible configurations after removing Trees node N. 80 Removing an Entry, Node Has Two Children Removing an Entry, Node Has Two Children Two possible configurations of node N that has two children. Node N and its subtrees; (a) entry a is immediately before e, b is immediately after e; (b) after deleting the node that contained a and replacing e with a. Trees 81 Trees 82 Removing an Entry, Node Has Two Children Removing an Entry, Node Has Two Children The largest entry a in node N's left subtree occurs in the subtree's rightmost node R. Trees 83 (a) A binary search tree; Trees (b) after removing Chad; 84

15 Removing an Entry, Node Has Two Children Removing an Entry in the Root (a) Two possible configurations of a root that has one child; (b) after removing the root. (c) after removing Sean; Trees (d) after removing Kathy. 85 Trees 86 Iterative Implementation To locate the desired entry The remove method given entry to be matched If remove finds the entry, it returns the entry If not, it returns null The compareto method used to make comparisons with the entries in the tree Recursive Implementation Details similar to adding an entry The public remove method calls a private recursive remove method The public remove returns removed entry Privateremove must return root of revised tree Thus use parameter that is an instance of ReturnObject to return the value the public remove needs Trees 87 Trees 88 Efficiency of Operations Efficiency of Operations Operations add, remove, getentry require a search that begins at the root Maximum number of comparisons is directly proportional to the height, h of the tree These operations are O(h) Thus we desire the shortest binary search tree we can create from the data Two binary search trees that contain the same data. Trees 89 Shorter tree has efficiency O(log n) Trees 90

16 Importance of Balance Importance of Balance Completely balanced Subtrees of each node have exactly same height Height balanced Subtrees of each node in the tree differ in height by no more than 1 Completely balanced or height balanced trees are balanced Some binary trees that are height balanced. Trees 91 Trees 92 Importance of Balance The order in which entries are added affect the shape of the tree If entries are added to an empty binary tree Best not to have them sorted first Tree is more balanced if entries are in random order Trees 93 Implementation of the ADT Dictionary Interface for a dictionary import java.util.iterator; public interface DictionaryInterface { public Object add(object key, Object value); public Object remove(object key); public Object getvalue(object key); public boolean contains(object key); public Iterator getkeyiterator(); public Iterator getvalueiterator(); public boolean isempty(); public int getsize(); public void clear(); } // end DictionaryInterface Trees 94 Implementation of the ADT Dictionary Class of data entries (can be private, internal to class Dictionary) private class Entry implements Comparable, java.io.serializable { private Object key; private Object value; private Entry(Object searchkey, Object datavalue) { key = searchkey; value = datavalue; } // end constructor public int compareto(object other) { Comparable ckey = (Comparable)key; return ckey.compareto(((entry)other).key); } < The class also defines the methods getkey, getvalue, and setvalue; no setkey method is provided. >... } // end Entry Trees 95 Implementation of the ADT Dictionary Beginning of class Dictionary import java.util.iterator; public class Dictionary implements DictionaryInterface, java.io.serializable { private SearchTreeInterface bst; public Dictionary() { bst = new BinarySearchTree(); } // end default constructor... } // end Dictionary Trees 96

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

Chapter Contents. Trees. Tree Concepts. Hierarchical Organization. Hierarchical Organization. Hierarchical Organization. Chapter Contents Chapter 18 Tree Concepts Hierarchical Organizations Tree Terminology Traversals of a Tree Traversals of a Binary Tree Traversals of a General Tree Java Interfaces for Interfaces for All

More information

A Binary Search Tree Implementation

A Binary Search Tree Implementation A Binary Search Tree Implementation Chapter 25 Getting Started Contents An Interface for the Binary Search Tree Duplicate Entries Beginning the Class Definition Searching and Retrieving Traversing Adding

More information

CS302 - Data Structures using C++

CS302 - Data Structures using C++ CS302 - Data Structures using C++ Topic: Trees Kostas Alexis Trees List, stacks, and queues are linear in their organization of data. Items are one after another In this section, we organize data in a

More information

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

Chapter 11.!!!!Trees! 2011 Pearson Addison-Wesley. All rights reserved 11 A-1 Chapter 11!!!!Trees! 2011 Pearson Addison-Wesley. All rights reserved 11 A-1 2015-12-01 09:30:53 1/54 Chapter-11.pdf (#13) Terminology Definition of a general tree! A general tree T is a set of one or

More information

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

Chapter 11.!!!!Trees! 2011 Pearson Addison-Wesley. All rights reserved 11 A-1 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

More information

Motivation Computer Information Systems Storage Retrieval Updates. Binary Search Trees. OrderedStructures. Binary Search Tree

Motivation Computer Information Systems Storage Retrieval Updates. Binary Search Trees. OrderedStructures. Binary Search Tree Binary Search Trees CMPUT 115 - Lecture Department of Computing Science University of Alberta Revised 21-Mar-05 In this lecture we study an important data structure: Binary Search Tree (BST) Motivation

More information

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

Lec 17 April 8. Topics: binary Trees expression trees. (Chapter 5 of text) Lec 17 April 8 Topics: binary Trees expression trees Binary Search Trees (Chapter 5 of text) Trees Linear access time of linked lists is prohibitive Heap can t support search in O(log N) time. (takes O(N)

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 11: Binary Search Trees MOUNA KACEM mouna@cs.wisc.edu Fall 2018 General Overview of Data Structures 2 Introduction to trees 3 Tree: Important non-linear data structure

More information

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

Tree Structures. A hierarchical data structure whose point of entry is the root node Binary Trees 1 Tree Structures A tree is A hierarchical data structure whose point of entry is the root node This structure can be partitioned into disjoint subsets These subsets are themselves trees and

More information

Binary Trees, Binary Search Trees

Binary Trees, Binary Search Trees Binary Trees, Binary Search Trees Trees Linear access time of linked lists is prohibitive Does there exist any simple data structure for which the running time of most operations (search, insert, delete)

More information

CS302 - Data Structures using C++

CS302 - Data Structures using C++ CS302 - Data Structures using C++ Topic: Implementation Kostas Alexis s Definition: A (BST) is a binary tree where each node has a Comparable key (and an associated value) and satisfies the restriction

More information

Principles of Computer Science

Principles of Computer Science Principles of Computer Science Binary Trees 08/11/2013 CSCI 2010 - Binary Trees - F.Z. Qureshi 1 Today s Topics Extending LinkedList with Fast Search Sorted Binary Trees Tree Concepts Traversals of a Binary

More information

CS302 Data Structures using C++

CS302 Data Structures using C++ CS302 Data Structures using C++ Study Guide for the Final Exam Fall 2018 Revision 1.1 This document serves to help you prepare towards the final exam for the Fall 2018 semester. 1. What topics are to be

More information

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

Trees 11/15/16. Chapter 11. Terminology. Terminology. Terminology. Terminology. Terminology Chapter 11 Trees 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

More information

Binary Search Trees. BinaryTree<E> Class (cont.) Section /27/2017

Binary Search Trees. BinaryTree<E> Class (cont.) Section /27/2017 Binary Search Trees Section.4 BinaryTree Class (cont.) public class BinaryTree { // Data members/fields...just the root is needed - Node root; // Constructor(s) + BinaryTree() + BinaryTree(Node

More information

BBM 201 Data structures

BBM 201 Data structures BBM 201 Data structures Lecture 11: Trees 2018-2019 Fall Content Terminology The Binary Tree The Binary Search Tree Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, 2013

More information

tree nonlinear Examples

tree nonlinear Examples The Tree ADT Objectives Define trees as data structures Define the terms associated with trees Discuss tree traversal algorithms Discuss a binary tree implementation Examine a binary tree example 10-2

More information

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

Terminology. The ADT Binary Tree. The ADT Binary Search Tree Terminology The ADT Binary Tree The ADT Binary Search Tree 1 Terminology 3 A general tree A general tree T is a set of one or more nodes such that T is partitioned into disjoint subsets: o A single node

More information

Topic 14. The BinaryTree ADT

Topic 14. The BinaryTree ADT Topic 14 The BinaryTree ADT Objectives Define trees as data structures Define the terms associated with trees Discuss tree traversal algorithms Discuss a binary tree implementation Examine a binary tree

More information

CS302 - Data Structures using C++

CS302 - Data Structures using C++ CS302 - Data Structures using C++ Topic: Tree Implementations Kostas Alexis Nodes in a Binary Tree Representing tree nodes Must contain both data and pointers to node s children Each node will be an object

More information

Trees, Binary Trees, and Binary Search Trees

Trees, Binary Trees, and Binary Search Trees COMP171 Trees, Binary Trees, and Binary Search Trees 2 Trees Linear access time of linked lists is prohibitive Does there exist any simple data structure for which the running time of most operations (search,

More information

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

Tree. A path is a connected sequence of edges. A tree topology is acyclic there is no loop. Tree A tree consists of a set of nodes and a set of edges connecting pairs of nodes. A tree has the property that there is exactly one path (no more, no less) between any pair of nodes. A path is a connected

More information

Garbage Collection: recycling unused memory

Garbage Collection: recycling unused memory Outline backtracking garbage collection trees binary search trees tree traversal binary search tree algorithms: add, remove, traverse binary node class 1 Backtracking finding a path through a maze is an

More information

Trees. CSE 373 Data Structures

Trees. CSE 373 Data Structures Trees CSE 373 Data Structures Readings Reading Chapter 7 Trees 2 Why Do We Need Trees? Lists, Stacks, and Queues are linear relationships Information often contains hierarchical relationships File directories

More information

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

Trees. (Trees) Data Structures and Programming Spring / 28 Trees (Trees) Data Structures and Programming Spring 2018 1 / 28 Trees A tree is a collection of nodes, which can be empty (recursive definition) If not empty, a tree consists of a distinguished node r

More information

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

About This Lecture. Trees. Outline. Recursive List Definition slide 1. Recursive Tree Definition. Recursive List Definition slide 2 Revised 21-Mar-05 About This Lecture 2 Trees In this lecture we study a non-linear container called a Tree and a special kind of Tree called a Binary Tree. CMPUT 115 - Lecture 18 Department of Computing

More information

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

void insert( Type const & ) void push_front( Type const & ) 6.1 Binary Search Trees A binary search tree is a data structure that can be used for storing sorted data. We will begin by discussing an Abstract Sorted List or Sorted List ADT and then proceed to describe

More information

a graph is a data structure made up of nodes in graph theory the links are normally called edges

a graph is a data structure made up of nodes in graph theory the links are normally called edges 1 Trees Graphs a graph is a data structure made up of nodes each node stores data each node has links to zero or more nodes in graph theory the links are normally called edges graphs occur frequently in

More information

Chapter 20: Binary Trees

Chapter 20: Binary Trees Chapter 20: Binary Trees 20.1 Definition and Application of Binary Trees Definition and Application of Binary Trees Binary tree: a nonlinear linked list in which each node may point to 0, 1, or two other

More information

ITI Introduction to Computing II

ITI Introduction to Computing II ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Binary search tree (part I) Version of March 24, 2013 Abstract These lecture notes are meant

More information

Binary Trees

Binary Trees Binary Trees 4-7-2005 Opening Discussion What did we talk about last class? Do you have any code to show? Do you have any questions about the assignment? What is a Tree? You are all familiar with what

More information

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

A set of nodes (or vertices) with a single starting point Binary Search Trees Understand tree terminology Understand and implement tree traversals Define the binary search tree property Implement binary search trees Implement the TreeSort algorithm 2 A set of

More information

TREES. Trees - Introduction

TREES. Trees - Introduction TREES Chapter 6 Trees - Introduction All previous data organizations we've studied are linear each element can have only one predecessor and successor Accessing all elements in a linear sequence is O(n)

More information

ITI Introduction to Computing II

ITI Introduction to Computing II ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Binary search tree (part I) Version of March 24, 2013 Abstract These lecture notes are meant

More information

Binary Trees. Height 1

Binary Trees. Height 1 Binary Trees Definitions A tree is a finite set of one or more nodes that shows parent-child relationship such that There is a special node called root Remaining nodes are portioned into subsets T1,T2,T3.

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 10: Search and Heaps MOUNA KACEM mouna@cs.wisc.edu Spring 2018 Search and Heaps 2 Linear Search Binary Search Introduction to trees Priority Queues Heaps Linear Search

More information

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

Trees : Part 1. Section 4.1. Theory and Terminology. A Tree? A Tree? Theory and Terminology. Theory and Terminology Trees : Part Section. () (2) Preorder, Postorder and Levelorder Traversals Definition: A tree is a connected graph with no cycles Consequences: Between any two vertices, there is exactly one unique path

More information

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

CS200: Trees. Rosen Ch & 11.3 Prichard Ch. 11. CS200 - Trees CS200: Trees Rosen Ch. 11.1 & 11.3 Prichard Ch. 11 1 Trees A A node has only one parent! Except the root: zero parents B C D E F Tree grows top to bottom! 2 Tree Terminology Node interior node path root

More information

Tree Structures. Definitions: o A tree is a connected acyclic graph. o A disconnected acyclic graph is called a forest

Tree Structures. Definitions: o A tree is a connected acyclic graph. o A disconnected acyclic graph is called a forest Tree Structures Definitions: o A tree is a connected acyclic graph. o A disconnected acyclic graph is called a forest o A tree is a connected digraph with these properties: There is exactly one node (Root)

More information

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

Tree Terminology. root. Edge. interior node. parent. path. subtree. child. leaf Tree Terminology Binary Trees CS00: Trees interior node Node path root parent Edge subtree Degree? Depth/Level? A binary tree is a set T of nodes such that either T is empty, or T is partitioned into three

More information

COMP : Trees. COMP20012 Trees 219

COMP : Trees. COMP20012 Trees 219 COMP20012 3: Trees COMP20012 Trees 219 Trees Seen lots of examples. Parse Trees Decision Trees Search Trees Family Trees Hierarchical Structures Management Directories COMP20012 Trees 220 Trees have natural

More information

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

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer) COSC 2007 Data Structures II Final Exam Thursday, April 13 th, 2006 This is a closed book and closed notes exam. There are total 3 parts. Please answer the questions in the provided space and use back

More information

CmpSci 187: Programming with Data Structures Spring 2015

CmpSci 187: Programming with Data Structures Spring 2015 CmpSci 187: Programming with Data Structures Spring 2015 Lecture #17, Implementing Binary Search Trees John Ridgway April 2, 2015 1 Implementing Binary Search Trees Review: The BST Interface Binary search

More information

Why Do We Need Trees?

Why Do We Need Trees? CSE 373 Lecture 6: Trees Today s agenda: Trees: Definition and terminology Traversing trees Binary search trees Inserting into and deleting from trees Covered in Chapter 4 of the text Why Do We Need Trees?

More information

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

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

More information

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

CSCI-401 Examlet #5. Name: Class: Date: True/False Indicate whether the sentence or statement is true or false. Name: Class: Date: CSCI-401 Examlet #5 True/False Indicate whether the sentence or statement is true or false. 1. The root node of the standard binary tree can be drawn anywhere in the tree diagram. 2.

More information

Data Structures and Algorithms for Engineers

Data Structures and Algorithms for Engineers 04-630 Data Structures and Algorithms for Engineers David Vernon Carnegie Mellon University Africa vernon@cmu.edu www.vernon.eu Data Structures and Algorithms for Engineers 1 Carnegie Mellon University

More information

CS211, LECTURE 20 SEARCH TREES ANNOUNCEMENTS:

CS211, LECTURE 20 SEARCH TREES ANNOUNCEMENTS: CS211, LECTURE 20 SEARCH TREES ANNOUNCEMENTS: OVERVIEW: motivation naive tree search sorting for trees and binary trees new tree classes search insert delete 1. Motivation 1.1 Search Structure continuing

More information

Tree: non-recursive definition. Trees, Binary Search Trees, and Heaps. Tree: recursive definition. Tree: example.

Tree: non-recursive definition. Trees, Binary Search Trees, and Heaps. Tree: recursive definition. Tree: example. Trees, Binary Search Trees, and Heaps CS 5301 Fall 2013 Jill Seaman Tree: non-recursive definition Tree: set of nodes and directed edges - root: one node is distinguished as the root - Every node (except

More information

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

Trees! Ellen Walker! CPSC 201 Data Structures! Hiram College! Trees! Ellen Walker! CPSC 201 Data Structures! Hiram College! ADTʼs Weʼve Studied! Position-oriented ADT! List! Stack! Queue! Value-oriented ADT! Sorted list! All of these are linear! One previous item;

More information

The Problem with Linked Lists. Topic 18. Attendance Question 1. Binary Search Trees. -Monty Python and The Holy Grail

The Problem with Linked Lists. Topic 18. Attendance Question 1. Binary Search Trees. -Monty Python and The Holy Grail Topic 18 Binary Search Trees "Yes. Shrubberies are my trade. I am a shrubber. My name is 'Roger the Shrubber'. I arrange, design, and sell shrubberies." -Monty Python and The Holy Grail The Problem with

More information

Announcements. Midterm exam 2, Thursday, May 18. Today s topic: Binary trees (Ch. 8) Next topic: Priority queues and heaps. Break around 11:45am

Announcements. Midterm exam 2, Thursday, May 18. Today s topic: Binary trees (Ch. 8) Next topic: Priority queues and heaps. Break around 11:45am Announcements Midterm exam 2, Thursday, May 18 Closed book/notes but one sheet of paper allowed Covers up to stacks and queues Today s topic: Binary trees (Ch. 8) Next topic: Priority queues and heaps

More information

Data Structures in Java

Data Structures in Java Data Structures in Java Lecture 9: Binary Search Trees. 10/7/015 Daniel Bauer 1 Contents 1. Binary Search Trees. Implementing Maps with BSTs Map ADT A map is collection of (key, value) pairs. Keys are

More information

Binary Trees Fall 2018 Margaret Reid-Miller

Binary Trees Fall 2018 Margaret Reid-Miller Binary Trees 15-121 Fall 2018 Margaret Reid-Miller Trees Fall 2018 15-121 (Reid-Miller) 2 Binary Trees A binary tree is either empty or it contains a root node and left- and right-subtrees that are also

More information

Hierarchical data structures. Announcements. Motivation for trees. Tree overview

Hierarchical data structures. Announcements. Motivation for trees. Tree overview Announcements Midterm exam 2, Thursday, May 18 Closed book/notes but one sheet of paper allowed Covers up to stacks and queues Today s topic: Binary trees (Ch. 8) Next topic: Priority queues and heaps

More information

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

! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge Trees & Heaps Week 12 Gaddis: 20 Weiss: 21.1-3 CS 5301 Fall 2018 Jill Seaman!1 Tree: non-recursive definition! Tree: set of nodes and directed edges - root: one node is distinguished as the root - Every

More information

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

Trees Chapter 19, 20. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013 Trees Chapter 19, 20 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013 2 Scope Trees: Trees as data structures Tree terminology Tree implementations Analyzing tree efficiency Tree traversals

More information

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

CISC 235 Topic 3. General Trees, Binary Trees, Binary Search Trees CISC 235 Topic 3 General Trees, Binary Trees, Binary Search Trees Outline General Trees Terminology, Representation, Properties Binary Trees Representations, Properties, Traversals Recursive Algorithms

More information

Data Structures. Giri Narasimhan Office: ECS 254A Phone: x-3748

Data Structures. Giri Narasimhan Office: ECS 254A Phone: x-3748 Data Structures Giri Narasimhan Office: ECS 254A Phone: x-3748 giri@cs.fiu.edu Search Tree Structures Binary Tree Operations u Tree Traversals u Search O(n) calls to visit() Why? Every recursive has one

More information

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

DATA STRUCTURES AND ALGORITHMS. Hierarchical data structures: AVL tree, Bayer tree, Heap DATA STRUCTURES AND ALGORITHMS Hierarchical data structures: AVL tree, Bayer tree, Heap Summary of the previous lecture TREE is hierarchical (non linear) data structure Binary trees Definitions Full tree,

More information

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

Data Structure Lecture#10: Binary Trees (Chapter 5) U Kang Seoul National University Data Structure Lecture#10: Binary Trees (Chapter 5) U Kang Seoul National University U Kang (2016) 1 In This Lecture The concept of binary tree, its terms, and its operations Full binary tree theorem Idea

More information

CMPSCI 187: Programming With Data Structures. Lecture #26: Binary Search Trees David Mix Barrington 9 November 2012

CMPSCI 187: Programming With Data Structures. Lecture #26: Binary Search Trees David Mix Barrington 9 November 2012 CMPSCI 187: Programming With Data Structures Lecture #26: Binary Search Trees David Mix Barrington 9 November 2012 Binary Search Trees Why Binary Search Trees? Trees, Binary Trees and Vocabulary The BST

More information

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

Also, recursive methods are usually declared private, and require a public non-recursive method to initiate them. Laboratory 11: Expression Trees and Binary Search Trees Introduction Trees are nonlinear objects that link nodes together in a hierarchical fashion. Each node contains a reference to the data object, a

More information

IX. Binary Trees (Chapter 10)

IX. Binary Trees (Chapter 10) IX. Binary Trees (Chapter 10) -1- A. Introduction: Searching a linked list. 1. Linear Search /* To linear search a list for a particular Item */ 1. Set Loc = 0; 2. Repeat the following: a. If Loc >= length

More information

CS 206 Introduction to Computer Science II

CS 206 Introduction to Computer Science II CS 206 Introduction to Computer Science II 10 / 10 / 2016 Instructor: Michael Eckmann Today s Topics Questions? Comments? A few comments about Doubly Linked Lists w/ dummy head/tail Trees Binary trees

More information

March 20/2003 Jayakanth Srinivasan,

March 20/2003 Jayakanth Srinivasan, Definition : A simple graph G = (V, E) consists of V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements of V called edges. Definition : In a multigraph G = (V, E) two or

More information

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

Trees. Q: Why study trees? A: Many advance ADTs are implemented using tree-based data structures. Trees Q: Why study trees? : Many advance DTs are implemented using tree-based data structures. Recursive Definition of (Rooted) Tree: Let T be a set with n 0 elements. (i) If n = 0, T is an empty tree,

More information

CMSC 341 Lecture 10 Binary Search Trees

CMSC 341 Lecture 10 Binary Search Trees CMSC 341 Lecture 10 Binary Search Trees John Park Based on slides from previous iterations of this course Review: Tree Traversals 2 Traversal Preorder, Inorder, Postorder H X M A K B E N Y L G W UMBC CMSC

More information

INF2220: algorithms and data structures Series 1

INF2220: algorithms and data structures Series 1 Universitetet i Oslo Institutt for Informatikk A. Maus, R.K. Runde, I. Yu INF2220: algorithms and data structures Series 1 Topic Trees & estimation of running time (Exercises with hints for solution) Issued:

More information

Cpt S 122 Data Structures. Data Structures Trees

Cpt S 122 Data Structures. Data Structures Trees Cpt S 122 Data Structures Data Structures Trees Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Motivation Trees are one of the most important and extensively

More information

Data Structures and Algorithms

Data Structures and Algorithms Data Structures and Algorithms CS245-2017S-06 Binary Search Trees David Galles Department of Computer Science University of San Francisco 06-0: Ordered List ADT Operations: Insert an element in the list

More information

Binary Trees. Reading: Lewis & Chase 12.1, 12.3 Eck Programming Course CL I

Binary Trees. Reading: Lewis & Chase 12.1, 12.3 Eck Programming Course CL I inary Trees Reading: Lewis & hase 12.1, 12.3 Eck 9.4.1 Objectives Tree basics Learn the terminology used when talking about trees iscuss methods for traversing trees iscuss a possible implementation of

More information

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

! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge Trees (& Heaps) Week 12 Gaddis: 20 Weiss: 21.1-3 CS 5301 Spring 2015 Jill Seaman 1 Tree: non-recursive definition! Tree: set of nodes and directed edges - root: one node is distinguished as the root -

More information

Advanced Java Concepts Unit 5: Trees. Notes and Exercises

Advanced Java Concepts Unit 5: Trees. Notes and Exercises Advanced Java Concepts Unit 5: Trees. Notes and Exercises A Tree is a data structure like the figure shown below. We don t usually care about unordered trees but that s where we ll start. Later we will

More information

Lecture 26. Introduction to Trees. Trees

Lecture 26. Introduction to Trees. Trees Lecture 26 Introduction to Trees Trees Trees are the name given to a versatile group of data structures. They can be used to implement a number of abstract interfaces including the List, but those applications

More information

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

If you took your exam home last time, I will still regrade it if you want. Some Comments about HW2: 1. You should have used a generic node in your structure one that expected an Object, and not some other type. 2. Main is still too long for some people 3. braces in wrong place,

More information

BINARY TREES, THE SEARCH TREE ADT BINARY SEARCH TREES, RED BLACK TREES, TREE TRAVERSALS, B TREES WEEK - 6

BINARY TREES, THE SEARCH TREE ADT BINARY SEARCH TREES, RED BLACK TREES, TREE TRAVERSALS, B TREES WEEK - 6 Ashish Jamuda Week 6 CS 331 DATA STRUCTURES & ALGORITHMS BINARY TREES, THE SEARCH TREE ADT BINARY SEARCH TREES, RED BLACK TREES, TREE TRAVERSALS, B TREES OBJECTIVES: Binary Trees Binary Search Trees Tree

More information

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

Data Structures. Trees. By Dr. Mohammad Ali H. Eljinini. M.A. Eljinini, PhD Data Structures Trees By Dr. Mohammad Ali H. Eljinini Trees Are collections of items arranged in a tree like data structure (none linear). Items are stored inside units called nodes. However: We can use

More information

CS302 - Data Structures using C++

CS302 - Data Structures using C++ CS302 - Data Structures using C++ Topic: Heaps Kostas Alexis The ADT Heap A heap is a complete binary tree that is either: Empty or Whose root contains a value >= each of its children and has heaps as

More information

CS200 Midterm 2 Fall 2007

CS200 Midterm 2 Fall 2007 CS200 Midterm 2 Fall 2007 Name Topic Possible Received Generics, programming 10 Trees 35 Priority Queues, Heaps 30 Graphs 25 TOTAL 100 1. Generics/Programming [10 points] a. [4 points] Why is it important

More information

Tables, Priority Queues, Heaps

Tables, Priority Queues, Heaps Tables, Priority Queues, Heaps Table ADT purpose, implementations Priority Queue ADT variation on Table ADT Heaps purpose, implementation heapsort EECS 268 Programming II 1 Table ADT A table in generic

More information

Binary Search Trees Treesort

Binary Search Trees Treesort Treesort CS 311 Data Structures and Algorithms Lecture Slides Friday, November 13, 2009 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks CHAPPELLG@member.ams.org 2005 2009

More information

CMSC 341. Binary Search Trees CMSC 341 BST

CMSC 341. Binary Search Trees CMSC 341 BST CMSC 341 Binary Search Trees CMSC 341 BST Announcements Homework #3 dues Thursday (10/5/2017) Exam #1 next Thursday (10/12/2017) CMSC 341 BST A Generic Tree CMSC 341 BST Binary Tree CMSC 341 BST The Binary

More information

Binary Trees. College of Computing & Information Technology King Abdulaziz University. CPCS-204 Data Structures I

Binary Trees. College of Computing & Information Technology King Abdulaziz University. CPCS-204 Data Structures I Binary Trees College of Computing & Information Technology King Abdulaziz University CPCS-204 Data Structures I Outline Tree Stuff Trees Binary Trees Implementation of a Binary Tree Tree Traversals Depth

More information

Definitions A A tree is an abstract t data type. Topic 17. "A tree may grow a. its leaves will return to its roots." Properties of Trees

Definitions A A tree is an abstract t data type. Topic 17. A tree may grow a. its leaves will return to its roots. Properties of Trees Topic 17 Introduction ti to Trees "A tree may grow a thousand feet tall, but its leaves will return to its roots." -Chinese Proverb Definitions A A tree is an abstract t data t d internal type nodes one

More information

CS 231 Data Structures and Algorithms Fall Recursion and Binary Trees Lecture 21 October 24, Prof. Zadia Codabux

CS 231 Data Structures and Algorithms Fall Recursion and Binary Trees Lecture 21 October 24, Prof. Zadia Codabux CS 231 Data Structures and Algorithms Fall 2018 Recursion and Binary Trees Lecture 21 October 24, 2018 Prof. Zadia Codabux 1 Agenda ArrayQueue.java Recursion Binary Tree Terminologies Traversal 2 Administrative

More information

Binary Tree. Preview. Binary Tree. Binary Tree. Binary Search Tree 10/2/2017. Binary Tree

Binary Tree. Preview. Binary Tree. Binary Tree. Binary Search Tree 10/2/2017. Binary Tree 0/2/ Preview Binary Tree Tree Binary Tree Property functions In-order walk Pre-order walk Post-order walk Search Tree Insert an element to the Tree Delete an element form the Tree A binary tree is a tree

More information

Binary Search Trees 1

Binary Search Trees 1 Binary Search Trees 1 The Problem with Linked Lists 8Accessing a item from a linked list takes O(N) time for an arbitrary element 8Binary trees can improve upon this and reduce access to O( log N ) time

More information

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

Uses for Trees About Trees Binary Trees. Trees. Seth Long. January 31, 2010 Uses for About Binary January 31, 2010 Uses for About Binary Uses for Uses for About Basic Idea Implementing Binary Example: Expression Binary Search Uses for Uses for About Binary Uses for Storage Binary

More information

STUDENT LESSON AB30 Binary Search Trees

STUDENT LESSON AB30 Binary Search Trees STUDENT LESSON AB30 Binary Search Trees Java Curriculum for AP Computer Science, Student Lesson AB30 1 STUDENT LESSON AB30 Binary Search Trees INTRODUCTION: A binary tree is a different kind of data structure

More information

Binary Trees and Binary Search Trees

Binary Trees and Binary Search Trees Binary Trees and Binary Search Trees Learning Goals After this unit, you should be able to... Determine if a given tree is an instance of a particular type (e.g. binary, and later heap, etc.) Describe

More information

Trees. Dr. Ronaldo Menezes Hugo Serrano Ronaldo Menezes, Florida Tech

Trees. Dr. Ronaldo Menezes Hugo Serrano Ronaldo Menezes, Florida Tech Trees Dr. Ronaldo Menezes Hugo Serrano (hbarbosafilh2011@my.fit.edu) Introduction to Trees Trees are very common in computer science They come in different variations They are used as data representation

More information

Chapter 5. Binary Trees

Chapter 5. Binary Trees Chapter 5 Binary Trees Definitions and Properties A binary tree is made up of a finite set of elements called nodes It consists of a root and two subtrees There is an edge from the root to its children

More information

Data Structures and Algorithms

Data Structures and Algorithms Data Structures and Algorithms Trees Sidra Malik sidra.malik@ciitlahore.edu.pk Tree? In computer science, a tree is an abstract model of a hierarchical structure A tree is a finite set of one or more nodes

More information

Trees. Eric McCreath

Trees. Eric McCreath Trees Eric McCreath 2 Overview In this lecture we will explore: general trees, binary trees, binary search trees, and AVL and B-Trees. 3 Trees Trees are recursive data structures. They are useful for:

More information

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

Computer Science 210 Data Structures Siena College Fall Topic Notes: Trees Computer Science 0 Data Structures Siena College Fall 08 Topic Notes: Trees We ve spent a lot of time looking at a variety of structures where there is a natural linear ordering of the elements in arrays,

More information

Topic Binary Trees (Non-Linear Data Structures)

Topic Binary Trees (Non-Linear Data Structures) Topic Binary Trees (Non-Linear Data Structures) CIS210 1 Linear Data Structures Arrays Linked lists Skip lists Self-organizing lists CIS210 2 Non-Linear Data Structures Hierarchical representation? Trees

More information

CS 234. Module 5. October 18, CS 234 Module 5 ADTS with items related by structure 1 / 25

CS 234. Module 5. October 18, CS 234 Module 5 ADTS with items related by structure 1 / 25 CS 234 Module 5 October 18, 2018 CS 234 Module 5 ADTS with items related by structure 1 / 25 ADTs representing structure We have seen ADTs where: There is no relation among items. Items are orderable types

More information

Generic BST Interface

Generic BST Interface Generic BST Interface Here s a partial generic BST interface: public class BST

More information

CS 206 Introduction to Computer Science II

CS 206 Introduction to Computer Science II CS 206 Introduction to Computer Science II 02 / 24 / 2017 Instructor: Michael Eckmann Today s Topics Questions? Comments? Trees binary trees two ideas for representing them in code traversals start binary

More information