Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 29

SLIIT ACADEMY

Higher Diploma in Information Technology–


Year 1, Semester 1

Computer Programming Techniques and Practices

Modeling Logic with Decision Trees and Decision Tables

Ruchira ManikkaArachchi
SLIIT Academy Pvt Ltd. © 2020
Intended Learning Outcomes

End of this lecture you will be able to learn ,


LO1:Undestand the concept of decision trees and decision tables.
LO2:Apply the knowledge to solve the problems.

SLIIT Academy Pvt Ltd. © 2020


Decision Trees and Decision Tables
• There are two main techniques available for analyzing and representing
complex processing logic:
o Decision trees
o Decision tables.
• However, it is to be noted that decision trees and decision tables have
much broader applicability than just specifying complex processing logic.

SLIIT Academy Pvt Ltd. © 2020


Decision Trees Vs. Decision Tables
• A decision tree gives a graphic view of the processing logic involved in
decision-making and the corresponding actions taken. The edges of a
decision tree represent conditions and the leaf nodes represent the
corresponding actions to be performed.
• Decision tables specify which variables are to be tested, what actions are
to be taken, and the order in which decision-making is to be performed.

SLIIT Academy Pvt Ltd. © 2020


Decision Trees
• A decision tree is a graphical view of:
• The logic involved in decision making (the order in which decisions
are made)
• The corresponding actions taken.
• Edges (branches) of a decision tree represent conditions to be tested.
• Nodes (leaves) of a decision tree represent actions to be performed.
The choice of actions depends on whether or not the various
conditions are satisfied SLIIT Academy Pvt Ltd. © 2020
Graphical Representation of a Decision tree

SLIIT Academy Pvt Ltd. © 2020


Steps to develop Decision Tree

o Step 01 : Identify the different conditions.

o Step 02: Identify the set of possible actions/outputs/responses.

o Step 03: Order the conditions based on their


priority .

Step 04: Begin building the tree from left to right while making sure you are
complete in listing all possible alternatives before moving over to the right.
SLIIT Academy Pvt Ltd. © 2020
Practice Question 01
There are different titles assigned to people depending on, the gender,
material status etc. Prepare a decision tree to find the title of a person
given the following details.
• If it is a male and single title is Mr
• If it is female and single title is Miss
• If it is male and married title is Mr
• If it is female and married title is Mrs
SLIIT Academy Pvt Ltd. © 2020
Step 01: Identify Conditions and Actions

• Gender
• Marital Status
Conditions

• Mr.
• Ms.
Actions • Mrs.

SLIIT Academy Pvt Ltd. © 2020


Sample Answer : Method 01

SLIIT Academy Pvt Ltd. © 2020


Sample Answer : Method 02

SLIIT Academy Pvt Ltd. © 2020


Sample Answer : Simplified Decision Tree(Method 01)

SLIIT Academy Pvt Ltd. © 2020


Sample Answer : Simplified Decision Tree(Method 02)

SLIIT Academy Pvt Ltd. © 2020


Decision Table
• A decision table shows processing logic in the form of conditions and actions
• The basic elements of a decision table are:
• Condition stub : Lists condition relevant to decision
These can be true (Y), false (N), or irrelevant/don’t care (–);
• Action stub :Actions that result from a given set of conditions
• Rules : if the given set of conditions is satisfied, then execute the
corresponding action.
SLIIT Academy Pvt Ltd. © 2020
Decision Table Layout
Standard format used for presenting decision tables.

Conditions being tested

Possible actions to take

SLIIT Academy Pvt Ltd. © 2020


Steps to develop Decision Tables

o Step 01 : Identify the different conditions.

o Step 02: Identify the set of possible actions/outputs/responses.

o Step 03: Determine number of rules.

SLIIT Academy Pvt Ltd. © 2020


Determine Number of rules : Example 01

Suppose we have two conditions with two possibilities.


Yes Yes

Condition 01 Condition 02

No No

No of rules = = 4

SLIIT Academy Pvt Ltd. © 2020


Determine Number of rules : Example 02

Suppose we have two conditions with different possibilities.


A Yes

Condition 01 B Condition 02
No
C
 

No of rules = * = 6

SLIIT Academy Pvt Ltd. © 2020


Practice Question 01 – Decision Table
There are different titles assigned to people depending on, the gender,
material status etc. Prepare a decision table to find the title of a person
given the following details.
• If it is a male and single title is Mr
• If it is female and single title is Miss
• If it is male and married title is Mr
• If it is female and married title is Mrs
SLIIT Academy Pvt Ltd. © 2020
Determine the no of rules
Conditions Possibilities
Gender Male Female

Marital Status Married Unmarried

 
No of Rules = =4

SLIIT Academy Pvt Ltd. © 2020


Sample Answer 01 : Decision Table
Conditions Rules

Gender Male Male Female Female

Marital Status Married Unmarried Married Unmarried

Actions

Mr. X X

Ms. X

Mrs. X

SLIIT Academy Pvt Ltd. © 2020


Sample Answer 02 : Decision Table
Conditions Rules

Gender is Male ? Yes Yes No No

Marital Status is Yes No Yes No


Married ?
Actions

Mr. X X

Ms. X

Mrs. X

SLIIT Academy Pvt Ltd. © 2020


Cleaning Things Up
• Check the table for any impossible situations, contradictions, and
redundancies and eliminate such rules.
• Rewrite the decision table with the most reduced set of rules;
rearranging the rule order is permissible if it improves user
understanding.

SLIIT Academy Pvt Ltd. © 2020


Simplified Decision Table
MARITAL STATUS
Conditions IS A DON’T CARE Rules
CONDITION
Gender Male Female Female
If the gender is
Marital Status - Married male ,Action
Unmarried
will not be
Actions depend on
marital Status
Mr. X
Ms. X
Mrs. X

SLIIT Academy Pvt Ltd. © 2020


Deciding Between Decision Tables & Decision Trees
Criteria Decision Tables Decision Trees

Portraying /complex logic Best Worst

Portraying simple rules Worst Best

Making decisions Worst Best


More compact Best Worst

Easier to manipulate Best Worst

SLIIT Academy Pvt Ltd. © 2020


Advantages & Disadvantages of decision tables
Advantages
• Provide a clear tabular representation linking conditions with actions
• Ensure coverage of all possible cases
• Highlight inconsistencies, redundancies, and ambiguities
• Easy to follow
Disadvantages
• Can become large and unwieldy
SLIIT Academy Pvt Ltd. © 2020
Steps to complete the Decision Table and Decision
Tree
o Step 01:Draw the decision table .
o Step 02:Draw the simplified decision table .(if can)
o Step 03:Draw the decision tree using the simplified decision table .

SLIIT Academy Pvt Ltd. © 2020


Practice Question 02
The Employee number (Eno) should be entered into the system. If the
employee gets a salary below Rs: 25000 and is unmarried, he is entitled to
receive 10% bonus. If the employee gets a salary equivalent or above Rs:
25000 and is unmarried, he is entitled to receive 8% bonus. All the
Married employees will get 15% bonus regardless of the salary amount.
The bonus percentage should be printed on the screen respectively.

SLIIT Academy Pvt Ltd. © 2020


Summary

• Decision Trees
• Decision Tables

SLIIT Academy Pvt Ltd. © 2020

You might also like