Today s topics
This presentation is the property of its rightful owner.
Sponsored Links
1 / 11

Today’s topics PowerPoint PPT Presentation


  • 39 Views
  • Uploaded on
  • Presentation posted in: General

Today’s topics. Java Implementing Decision Trees Upcoming More formal treatment of grammars Reading Great Ideas , Chapter 2. A decision tree Selecting a textbook. 3. yes. Oh! Pascal by D. Cooper. 1. A programming focus instead of theory. yes. 4. Algorithmics by D. Harel. 0.

Download Presentation

Today’s topics

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Today s topics

Today’s topics

Java

Implementing Decision Trees

Upcoming

More formal treatment of grammars

Reading

Great Ideas, Chapter 2


A decision tree selecting a textbook

A decision treeSelecting a textbook

3

yes

Oh! Pascal

by D. Cooper

1

A programming

focus instead

of theory

yes

4

Algorithmics

by D. Harel

0

Do you wish a

Mathematical

Approach?

no

yes

5

Karel the Robot

by R. Pattis

2

A narrow focus

instead of an

overview of CS

no

6

Great Ideas in CS

by A. Biermann

no


Implementing a decision tree

Implementing a Decision Tree

  • Start with a very very simple tree

    • Have just one level of decision

    • Need only one ifstatement

    • Have already done this kind of thing before

    • No new challenges


Code for simple tree

Code for Simple Tree

public class SimpBook extends java.applet.Applet implements ActionListener

{ TextField mQuery, mAnswer;

Button bYes, bNo;

public void init()

{ mQuery = new TextField(70);

mQuery.setText(

"Do you wish a mathematical approach?");

bYes = new Button("Yes");

bNo = new Button("No");

mAnswer = new TextField(70);

bYes.addActionListener(this);

bNo.addActionListener(this);

add(mQuery); add(bYes); add(bNo); add(mAnswer);

}


Code for simple tree part 2

Code for Simple Tree (part 2)

public void actionPerformed(ActionEvent event)

{

Object cause = event.getSource();

if (cause == bYes)

{

mAnswer.setText(

"Books by Harel or Cooper are nice.");

}

else// must have been the No button

{

mAnswer.setText(

"Books by Pattis or Biermann should do.");

}

}

}


The full decision tree

The Full Decision Tree

  • Now have more levels to worry about

    • Have picked up an additional problem

    • Need to keep track of where we are (or have been)

    • (Almost like exploring a cave -- )

    • (-- or putting book marks in a book)

  • Add a variable which is used to

    record where we’ve been

    • Use the numbers on our diagram for reference

      • (numbers are arbitrary; must be unique)

    • Named the variable myLocation to suggest use


Code for the decision tree

Code for the Decision Tree

public class BookPick extends java.applet.Applet implements ActionListener

{ TextField mQuery, mAnswer;

Button bYes, bNo;

int myLocation;

public void init()

{

mQuery = new TextField(70);

mQuery.setText("Do you wish a mathematical approach?");

bYes = new Button("Yes");

bNo = new Button("No");

myLocation = 0;

mAnswer = new TextField(70);

bYes.addActionListener(this);

bNo.addActionListener(this);

add(mQuery); add(bYes); add(bNo); add(mAnswer);

}


Code for the decision tree p 2

Code for the Decision Tree (p. 2)

public void actionPerformed(ActionEvent event)

{ Object cause = event.getSource();

if (myLocation == 0)

{

if (cause == bYes)

{

myLocation = 1;

mQuery.setText(

"A programming focus instead of theory?");

}

if (cause == bNo)

{

myLocation = 2;

mQuery.setText(

"Narrow focus instead of overview of CS?");

}

}


Code for the decision tree p 3

Code for the Decision Tree (p. 3)

elseif (myLocation == 1)

{

if (cause == bYes)

{

myLocation = 3;

mAnswer.setText(

"I recommend 'Oh! Pascal' by D. Cooper.");

}

if (cause == bNo)

{

myLocation = 4;

mAnswer.setText(

"'Algorithmics' by D. Harel is a fine book.");

}

}


Code for the decision tree p 4

Code for the Decision Tree (p. 4)

elseif (myLocation == 2)

{

if (cause == bYes)

{

myLocation = 5;

mAnswer.setText(

"Try 'Karel the Robot' by R. Pattis.");

}

if (cause == bNo)

{

myLocation = 6;

mAnswer.setText(

"Enjoy A. Biermann's 'Great Ideas in CS'");

}

}

}

}


General decision trees

General Decision Trees

  • How can we can extend this to any size tree?

  • Assume we can use yes or no answers all the way through

    • Notice that at each on the tree we have another tree

    • At each step we use code similar to our simple tree

    • Must keep track of where we’ve been

  • For more general branching (not just yes/no) need a bit more

    • Not hard to adapt

    • General ideas the same


  • Login