1 / 12

Binary Decision Tree

Binary Decision Tree. Computer Science and Engineering. 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 < key value of the root

Roberta
Télécharger la présentation

Binary Decision Tree

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Binary Decision Tree Computer Science and Engineering B.Ramamurthy

  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 < key value of the root • A set of keys in the right subtree > key value of the root • We considered only numerical values, > and < 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. B.Ramamurthy

  3. Is it an amphibian? Is it a wild animal? (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 B.Ramamurthy

  4. Simple Guesser: no load/save B.Ramamurthy

  5. Builder/Guesser with save/no load AnimalDBBuilder java.io.Serializable BTreeInterface ObjectOutputStream BTree Visitor OutputFile LearnVisitor PlayVisitor B.Ramamurthy

  6. Guesser with simple load/save GuesserSimpleLoadSave java.io.Serializable BTreeInterface ObjectOutputStream ObjectInputStream BTree Visitor OutputFile InputFile LearnVisitor PlayVisitor B.Ramamurthy

  7. OtherApplications Guesser with Load/Save Visitors GuesserLoadSave java.io.Serializable BTreeInterface ObjectOutputStream ObjectInputStream Visitor BTree OutputFile InputFile LearnVisitor PlayVisitor LoadVisitor SaveVisitor B.Ramamurthy

  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 B.Ramamurthy

  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. B.Ramamurthy

  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 ClassNotFoundException, IOException; B.Ramamurthy

  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); B.Ramamurthy

  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(); B.Ramamurthy

More Related