Binary Decision Tree - PowerPoint PPT Presentation

About This Presentation
Title:

Binary Decision Tree

Description:

... no load/save Builder/Guesser with save/no load Guesser with ... Is it an amphibian? no yes Cow Giraffe Tiger Frog Parrot no yes no yes no yes Questions ... – PowerPoint PPT presentation

Number of Views:67
Avg rating:3.0/5.0
Slides: 13
Provided by: cseBuffal4
Learn more at: https://cse.buffalo.edu
Category:
Tags: binary | decision | save | tiger | tree

less

Transcript and Presenter's Notes

Title: Binary Decision Tree


1
Binary Decision Tree
  • Computer Science and Engineering

2
Introduction
  • Binary Search Tree Key value at the root
    partitions the set of data represented in the
    tree into three disjoint sets
  • A set with key value at the root
  • A set of keys in the left subtree lt key value of
    the root
  • A set of keys in the right subtree gt key value of
    the root
  • We considered only numerical values, gt and lt
    operators.
  • In a decision tree the criteria for partition is
    stored in the internal node and the data in the
    leaf nodes. When the partition is two-way we get
    a binary decision tree.
  • Example
  • Tree for the popular animal guessing game
  • The criteria mammal could split the zoo animals
    into two sets, such other criteria could split
    the two sets further, until the splitting process
    results in a single animal kind.

3
(Zoo) Animal Tree
Is it a mammal?
no
yes
no
yes
yes
no
Frog
Parrot
Does it have a long neck?
Cow
yes
no
Questions with yes or no answers at the
internal nodes Answers at the leaf nodes.
Giraffe
Tiger
4
Simple Guesser no load/save
5
Builder/Guesser with save/no load
AnimalDBBuilder
BTreeInterface
java.io.Serializable
ObjectOutputStream
Visitor
BTree
OutputFile
PlayVisitor
LearnVisitor
6
Guesser with simple load/save
GuesserSimpleLoadSave
BTreeInterface
java.io.Serializable
ObjectOutputStream
ObjectInputStream
Visitor
BTree
OutputFile
InputFile
PlayVisitor
LearnVisitor
7
Guesser with Load/Save Visitors
GuesserLoadSave
BTreeInterface
java.io.Serializable
ObjectOutputStream
ObjectInputStream
Visitor
BTree
OutputFile
InputFile
PlayVisitor
LearnVisitor
LoadVisitor
SaveVisitor
8
Load/Save (using Object Streaming)
  • The capability to store and retrieve Java objects
    is essential to building persistence and
    streaming into application.
  • Writing to an Object Stream
  • Reading from an Object Stream
  • Exception Handling
  • Example See the code in the BTree example

9
Persistence
  • The values of the data structures in a program
    are lost when the program terminates.
  • If you want the data to exist after program
    termination you need to store it in a file or in
    a database.
  • This capability of data is known as persistence.

10
How to use Serialization?
  • 1. import java.io.
  • 2. Specify the class whose instances need to be
    stored/loaded as implementing java.io.Serializable
    interface.
  • 3. Use writeObject and readObject methods whose
    header are as given below
  • void writeObject (Object obj) throws
    IOException
  • Object readObject() throws ClassNotFoundExcepti
    on, IOException

11
Writing to an Object Stream
  • // serialize various objects into a file
  • FileOutputStream f new FileOutputStream(tmp)
  • ObjectOutputStream s new ObjectOutputStream(f)
  • s.writeObject(Today)
  • s.writeObject(new Date())
  • BTree t new BTree(MyName, null, null)
  • s.writeObject(t)

12
Reading from an Object Stream
  • // Deserialize a objects from a file
  • FileInputStream inf new FileInputStream(tmp)
  • ObjectInputStream s1 new ObjectInputStream(inf)
  • //read the Object and cast to retrieve the
  • // actual object
  • String (String)s1.readObject()
  • Data date (Date)s1.readObject()
  • BTree animalDB (BTree)s1.readObject()
Write a Comment
User Comments (0)
About PowerShow.com