




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
An in-depth exploration of trees as a non-linear hierarchical data structure. Topics covered include tree terminology, classifications (binary, balanced, complete, full), traversals (preorder, postorder, level-order), and various implementation techniques (array-based, linked nodes). The document also includes a brief introduction to decision trees and their applications.
Typology: Study notes
1 / 8
This page cannot be seen from the preview
Don't miss anything!
16.2 – Tree Traversals
16.2 – Pseudocode of PreInPost Traversals
Traverse (left) Visit Node Traverse (right)
Traverse (left) Traverse (right) Visit Node
Visit Node Traverse (left) Traverse (right) 16.2 – Level-Order Traversal
Enqueue the root node of the tree While the queue is not empty{ Dequeue node Visit node Enqueue left child of node Enqueue right child of node } 16.3 – Strategies for Implementing Trees Array-based implementations are the less obvious choice, but sometimes useful Computed Links in an Array: 0 1 2 3 4 5 6 7 A B C D E F A B C D E F G
16.4 – javafoundations.BinaryTree // Returns a reference to the element in the tree matching // the specified target. public T find (T target); // Returns true if the binary tree contains no elements, and // false otherwise. public boolean isEmpty(); // public Returns the int size(); number of elements in this binary tree. // Returns the string representation of the binary tree. public String toString(); // Returns a preorder traversal on the binary tree. public Iterator
16.4 – javafoundations.BTNode //******************************************************************* // BTNode.java Java Foundations // // Represents a node in a binary tree with a left and right child. // Therefore this class also represents the root of a subtree. //******************************************************************* package javafoundations; public class BTNode
16.4 – javafoundations.BTNode //----------------------------------------------------------------- // Sets the left child of this node. //----------------------------------------------------------------- public void setLeft (BTNode
16.4 – javafoundations.LinkedBinaryTree //----------------------------------------------------------------- // Populates and returns an iterator containing the elements in // //----------------------------------------------------------------- this binary tree using a levelorder traversal. public Iterator
16.5 – A Decision Tree for Diagnosing Back Pain
16.5 – BackPainAnalyzer.java //******************************************************************** // BackPainAnalyzer.java Java Foundations // // Demonstrates the use of a binary tree. //******************************************************************** public class BackPainAnalyzer { //----------------------------------------------------------------- // Asks questions of the user to diagnose a medical problem. //----------------------------------------------------------------- public static void main (String[] args) { BackPainExpert expert = new BackPainExpert(); expert.diagnose(); } } 16.5 – BackPainExpert.java //******************************************************************** // BackPainExpert.java Java Foundations // //******************************************************************** Represents a simple expert system for back pain diagnosis. import javafoundations.*; public class BackPainExpert { private LinkedBinaryTree