SlideShare a Scribd company logo
1 of 40
Download to read offline
Data Structures and Algorithms




      The Decision
      Logic Structure




   Some examples of conditional expressions are as
   follows :

        1.         A < B (A and B are the same the data type)
        2.         X + 5 >=Z (X and Z are numeric data)
        3.         E < 5 or F > 10 (E and F are numeric data)
        4.         DATAOK (DATAOK is a logical datum)




Problem Solving with Decisions                                *Property of STI
                                                                 Page 1 of 40
Data Structures and Algorithms




     The Decision
     Logic Structure




Multiple IF/THEN/ELSE
There are three types of decision logic you will use to
write algorithms for solutions consisting of more than
one decision. These types of decision logic include:

     · Straight-through logic
     · Positive logic
     · Negative Logic
Problem Solving with Decisions                        *Property of STI
                                                         Page 2 of 40
Data Structures and Algorithms




     The Decision
     Logic Structure

@ Single Condition – Two Possible Actions or Sets of
     Actions




Problem Solving with Decisions                      *Property of STI
                                                       Page 3 of 40
Data Structures and Algorithms




     The Decision
     Logic Structure



Straight-through logic
@ Means that all of the decisions are processed
      sequentially, one after the other.
@ There is no ELSE part of the instruction; the FALSE
      branch always goes to the next decision, and the
      TRUE branch goes to the next decision after the
      instructions for the TRUE branch have been
      processed.




Problem Solving with Decisions                            *Property of STI
                                                             Page 4 of 40
Data Structures and Algorithms




     The Decision
     Logic Structure


Positive Logic
@ Allows the flow of the processing to continue
      through the module instead of processing
      succeeding decisions, once the resultant of a
      decision is true.

@ Whenever the resultant is FALSE (the ELSE part of
      the decision), another decision in the sequence is
      processed until the resultant is TRUE, or there are
      no more decisions to process.

@ At that time, the FALSE branch processes the
      remaining instructions.




Problem Solving with Decisions                          *Property of STI
                                                           Page 5 of 40
Data Structures and Algorithms




     The Decision
     Logic Structure


Negative Logic
@ similar to positive logic except that the flow of the
     processing continues through the module when the
     resultant of a decision is FALSE

@ whenever the resultant is TRUE, another decision
     is processed until the resultant is FALSE, or there
     are no more decisions to process

@ at that time, the TRUE branch processes the
     remaining instructions

@ the hardest to use and understand




Problem Solving with Decisions                          *Property of STI
                                                           Page 6 of 40
Data Structures and Algorithms




     The Decision
     Logic Structure




Using Straight-through logic
Problem: Find the amount to charge people of varying ages
for a food ticket. When the person is under 16, the charge is
P7; when the person is 65 or over, the charge is P5; all others
are charged P10. The conditions are the following :

     AGE                         CHARGE
     AGE < 16                       7
     AGE >=16 and AGE < 65          10
     AGE >=65                       5
Problem Solving with Decisions                              *Property of STI
                                                               Page 7 of 40
Data Structures and Algorithms




     The Decision
     Logic Structure

Solution :

               Algorithm                     Flowchart
                                                  A



                 IF AGE < 16
                   THEN
       T             CHARGE = 7
                                              IF                T
                                            AGE < 16
                 IF AGE >= 16 AND AGE <65
                  THEN
           T         CHARGE = 10                             Charge = 7

                 IF AGE >= 65                 F
                   THEN
           T         CHARGE = 5                IF
                                            AGE >= 16           T
                                              and
                                            AGE < 65

                                                             Charge = 10

                                              F


                                               IF                   T
                                            AGE >= 65


                                                             Charge = 10

                                             F

                                                  B



Problem Solving with Decisions                                          *Property of STI
                                                                           Page 8 of 40
Data Structures and Algorithms




     The Decision
     Logic Structure


Problem: Change the value of X to 0 when X becomes
greater than 100, and to change the value of Y to 0
when Y becomes greater than 250

                         Algorithm      Flowchart
                                             A




                           IF X < 100
                             THEN           IF               T
                 T             X = 10    X > 100



                           IF Y > 250                        X=0

                            THEN
                     T                   F
                               Y=0

                                            IF               T
                                         Y > 250



                                                              Y=0

                                         F

                                             B



Problem Solving with Decisions                                    *Property of STI
                                                                     Page 9 of 40
Data Structures and Algorithms




      The Decision
      Logic Structure

Using Positive Logic
Problem: Find the amount to charge people of varying
ages for a food ticket. When the person is under 16,
the charge is P7; when the person is 65 or over, the
charge is P5; all others are charged P10. The conditions
are the following :
                                    Algorithm
                             IF AGE <16
                              THEN
                                 CHARGE = 7

                                 ELSE
                                    IF AGE < 65
                                       THEN
                                          CHARGE = 10
                                       ELSE
                                          CHARGE = 5


Problem Solving with Decisions                                   *Property of STI
                                                                   Page 10 of 40
Data Structures and Algorithms




      The Decision
      Logic Structure


                                            Flowchart

                                                        A




                                            F          IF          T
                                                    AGE < 16




                        F           IF          T
                                 AGE < 65                         CHARGE = 7




               CHARGE = 5                   CHARGE = 10




                                                    B




Problem Solving with Decisions                                                *Property of STI
                                                                                Page 11 of 40
Data Structures and Algorithms




      The Decision
      Logic Structure


Problem: Calculate the commission rate for a
salesperson, given the amount of sales. When the
salesperson has sold less than or equal to 2,000 worth
of goods, the commission is 2%. When the sales total is
more than 2,000 and less than or equal to 4,000, the
commission is 4%. When sales total is more than 4,000
and less than or equal to 6,000, the commission is 7%.
When the person has sold more than 6,000 the
commission is 10%. The conditions are the following:

                SALES            COMMISSION

          <=2000                    .02
     2001 – 4000                    .04
     4001 – 6000                    .07
          > 6000                    .10




Problem Solving with Decisions                        *Property of STI
                                                        Page 12 of 40
Data Structures and Algorithms




      The Decision
      Logic Structure

                            Solution 1: Algorithm
        IF SALES <= 2000
         THEN
            COMMISSION = .02
      T ELSE
            IF SALES <= 4000
               THEN
                  COMMISSION = .04
          T
               ELSE
                  IF SALES <= 6000
                     THEN
      F         T
                        COMMISSION = .07
          F          ELSE
                F       COMMISSION = .1




Problem Solving with Decisions                                     *Property of STI
                                                                     Page 13 of 40
Data Structures and Algorithms




      The Decision
      Logic Structure

                            Solution 1: Flowchart

                                                                     A



                                                       F                          T
                                                                    IF
                                                               SALES <=2000


                                         F                       T            COMMISSION =
                                                     IF                           .02
                                                SALES <=4000


                                                               COMMISSION
                       F              IF           T              = .04
                                 SALES <=6000


           COMMISSION                           COMMISSION
              = .1                                 = .07




                                                                              B




Problem Solving with Decisions                                                          *Property of STI
                                                                                          Page 14 of 40
Data Structures and Algorithms




      The Decision
      Logic Structure

                                 Solution 1: Test

       1. TEST FOR                          3. TEST FOR
          SALES = 1500                         SALES = 5500
          IS SALES <= 2000                     IS SALES <= 2000
              TRUE                                 FALSE
          COMMISSION = .02                     IS SALES <= 4000
                                                   FALSE
       2. TEST FOR                             IS SALES <= 6000
          SALES = 3500                             TRUE
          IS SALES <= 2000                     COMMISSION = .07
              FALSE
          IS SALES <= 4000                  4. TEST FOR
              TRUE                             SALES = 7500
          COMMISSION = .04                     IS SALES <= 2000
                                                   FALSE
                                               IS SALES <= 4000
                                                   FALSE
                                               IS SALES <= 6000
                                                   TRUE
                                               COMMISSION = .1

Problem Solving with Decisions                                     *Property of STI
                                                                     Page 15 of 40
Data Structures and Algorithms




      The Decision
      Logic Structure

                            Solution 2: Algorithm
        IF SALES > 6000
         THEN
            COMMISSION = .1
      T ELSE
            IF SALES > 4000
               THEN
                  COMMISSION = .07
          T
               ELSE
                  IF SALES > 2000
                     THEN
      F         T
                        COMMISSION = .04
          F          ELSE
                F       COMMISSION = .02




Problem Solving with Decisions                                     *Property of STI
                                                                     Page 16 of 40
Data Structures and Algorithms




      The Decision
      Logic Structure

                            Solution 2: Flowchart
                                                                 A



                                                   F                          T
                                                                IF
                                                           SALES > 6000


                                     F                       T            COMMISSION =
                                                 IF                            .1
                                            SALES > 4000


                                                           COMMISSION
                    F             IF           T              = .07
                             SALES > 2000


        COMMISSION                          COMMISSION
           = .02                               = .04




                                                                          B




Problem Solving with Decisions                                                      *Property of STI
                                                                                      Page 17 of 40
Data Structures and Algorithms




      The Decision
      Logic Structure

                                 Solution 2: Test

       1. SALES = 1500                       3. SALES = 5500
          IS SALES > 6000                       IS SALES > 6000
              FALSE                                 FALSE
          IS SALES > 4000                       IS SALES > 4000
              FALSE                                 TRUE
          IS SALES > 2000                       COMMISSION = .07
              FALSE
          COMMISSION = .02

       2. SALES = 3500                       4. SALES = 7500
          IS SALES > 6000                       IS SALES > 6000
              FALSE                                 TRUE
          IS SALES > 4000                       COMMISSION = .1
              FALSE
          IS SALES > 2000
              TRUE
          COMMISSION = .04



Problem Solving with Decisions                                     *Property of STI
                                                                     Page 18 of 40
Data Structures and Algorithms




      The Decision
      Logic Structure


Using Negative Logic
  @ Negative Logic is the hardest for most people to
        comprehend because they do not think in negative
        terms.

  @ In general when you use negative logic you are
        telling the computer to process another decision
        when the resultant condition is TRUE;

  @ If the resultant is FALSE, then the computer
        processes a consequent set of instructions and then
        continues processing the module.




Problem Solving with Decisions                            *Property of STI
                                                            Page 19 of 40
Data Structures and Algorithms




      The Decision
      Logic Structure


               Negative Logic Solution 1: Algorithm

                          IF AGE >= 16
                           THEN
                              IF AGE >= 65
                                 THEN
                                    CHARGE = 5
                                 ELSE
                                    CHARGE = 10

                             ELSE
                                CHARGE = 7




Problem Solving with Decisions                              *Property of STI
                                                              Page 20 of 40
Data Structures and Algorithms




      The Decision
      Logic Structure


              Negative Logic Solution 1: Flowchart

                                        A




                     F                                    T
                                        IF
                                     AGE >= 16




                                                  F                              T
           CHARGE = 7                                            IF
                                                              AGE >= 16




                                            CHARGE = 10                        CHARGE = 5




                                 B




Problem Solving with Decisions                                                           *Property of STI
                                                                                           Page 21 of 40
Data Structures and Algorithms




       The Decision
       Logic Structure

Negative Logic Solution 2: Algorithm

                 IF SALES > 2000
                  THEN
                     IF SALES > 4000
                        THEN
                           IF SALES > 6000
                              THEN
                                 COMMISSION = .1
                              ELSE
                                 COMMISSION = .07

                                 ELSE
                                    COMMISSION = .04

                            ELSE
                               COMMISSION = .02


Problem Solving with Decisions                                 *Property of STI
                                                                 Page 22 of 40
Data Structures and Algorithms




       The Decision
       Logic Structure

Negative Logic Solution 2: Flowchart
                                      A




                                     IF
                                 SALES > 2000




             COMMISSION =
                 .02                                  IF
                                                  SALES > 4000




                                   COMMISSION =
                                       .04                           IF
                                                                 SALES > 6000




                                                      COMMISSION =              COMMISSION =
                                                          .07                       .01




                             B



Problem Solving with Decisions                                                          *Property of STI
                                                                                          Page 23 of 40
Data Structures and Algorithms




       The Decision
       Logic Structure

Negative Logic Solution 2: TEST

     1. SALES = 1500             3. SALES = 5500
        IS SALES > 2000             IS SALES > 2000
            FALSE                       TRUE
        COMMISSION = .02            IS SALES > 4000
                                        TRUE
     2. SALES = 3500                IS SALES > 6000
        IS SALES > 2000                 FALSE
            TRUE                    COMMISSION = .1
        IS SALES > 4000
            FALSE                4. SALES = 7500
        COMMISSION = .04            IS SALES > 2000
                                        TRUE
                                    IS SALES > 4000
                                        TRUE
                                    IS SALES > 6000
                                        TRUE
                                    COMMISSION = .1


Problem Solving with Decisions                            *Property of STI
                                                            Page 24 of 40
Data Structures and Algorithms




      The Decision
      Logic Structure


Another Set-Up: Algorithm

         IF SALES <= 6000
          THEN
             IF SALES <= 4000
                THEN
                   IF SALES <= 2000
                      THEN
                         COMMISSION = .02
                      ELSE
                         COMMISSION = .04
                   ELSE
                      COMMISION = .07
                ELSE
                   COMMISSION = .1




Problem Solving with Decisions                   *Property of STI
                                                   Page 25 of 40
Data Structures and Algorithms




      The Decision
      Logic Structure


Another Set-Up: Flowchart
                                     A




               F                                    T
                                IF
                           SALES <= 6000



      CHARGE = .1                            F                          T
                                                         IF
                                                    SALES <= 4000



                                     COMMISSION =
                                          .07
                                                                 F          IF            T
                                                                       SALES <= 2000



                                                        COMMISSION =                   COMMISSION =
                                                             .04                            .02




                                 B




Problem Solving with Decisions                                                                *Property of STI
                                                                                                Page 26 of 40
Data Structures and Algorithms




       The Decision
       Logic Structure

Another Set-Up: Test
     1. SALES = 1500             3. SALES = 5500
        IS SALES <= 6000            IS SALES <= 6000
            TRUE                        TRUE
        IS SALES <= 4000            IS SALES <= 4000
            TRUE                        FALSE
        IS SALES <= 2000            COMMISSION = .07
            TRUE
        COMMISSION = .02

     2. SALES = 3500             4. SALES = 7500
        IS SALES <= 6000            IS SALES <= 6000
            TRUE                        FALSE
        IS SALES <= 4000            COMMISSION = .1
            TRUE
        IS SALES <= 2000
            FALSE
        COMMISSION = .04




Problem Solving with Decisions                         *Property of STI
                                                         Page 27 of 40
Data Structures and Algorithms




       The Decision
       Logic Structure

Logic Conversion

To convert from positive logic to negative logic or vice
versa, do the following :

      1.      Change all < to >=
      2.      Change all <= to >
      3.      Change all > to <=
      4.      Change all >= to <
      5.      Change all = to <>
      6.      Change all <> to =
      7.      Interchange all of the THEN set of instructions
              with the corresponding ELSE set of instructions.




Problem Solving with Decisions                               *Property of STI
                                                               Page 28 of 40
Data Structures and Algorithms




       The Decision
       Logic Structure

Conversion from Positive to Negative Logic




Problem Solving with Decisions                     *Property of STI
                                                     Page 29 of 40
Data Structures and Algorithms




       The Decision
       Logic Structure


Which Decision Logic?
To analyze which type of decision logic would be most
efficient for a particular solution, answer the following
questions:

1. Which type would make the solution most readable?
2. Which type would make the solution the easiest
   to maintain or change?
3. Which would require the fewest test when you
   don’t know anything about the data?
4. Which would require the fewest test when you’re
   given some data?




Problem Solving with Decisions                          *Property of STI
                                                          Page 30 of 40
Data Structures and Algorithms




       The Decision
       Logic Structure

Four ways to Design a Set of Conditions




Problem Solving with Decisions                   *Property of STI
                                                   Page 31 of 40
Data Structures and Algorithms




       The Decision
       Logic Structure

Decision Tables
A decision table consists of four parts:
 @     The conditions.
 @     The actions.
 @     The combinations of TRUE and FALSE for the conditions.
 @     The action to be taken or the consequences for each
       combination of conditions.

The four steps to develop a flowchart from the decision table
are :

 @ Draw all decisions in flowchart form.
 @ Compare the true and false sides of each decision, starting
   with the first one.
 @ Eliminate any decisions that have the same instructions
   on both the true and false sides, keeping the true
   consequence or action.
 @ Redraw the flowchart.



Problem Solving with Decisions                             *Property of STI
                                                             Page 32 of 40
Data Structures and Algorithms




       The Decision
       Logic Structure



Decision Table Format




Problem Solving with Decisions                  *Property of STI
                                                  Page 33 of 40
Data Structures and Algorithms




                The Decision
                Logic Structure




Problem Solving with Decisions                 *Property of STI
                                                 Page 34 of 40
Data Structures and Algorithms




                The Decision
                Logic Structure

                       Elimination of Conditions




Problem Solving with Decisions                                  *Property of STI
                                                                  Page 35 of 40
Data Structures and Algorithms




       The Decision
       Logic Structure

Final Flowchart




Problem Solving with Decisions                  *Property of STI
                                                  Page 36 of 40
Data Structures and Algorithms




       The Decision
       Logic Structure


Decision Table




Problem Solving with Decisions                  *Property of STI
                                                  Page 37 of 40
Data Structures and Algorithms




            The Decision
            Logic Structure
                      Starting Flowchart




Problem Solving with Decisions                          *Property of STI
                                                          Page 38 of 40
Data Structures and Algorithms




            The Decision
            Logic Structure
                      Elimination of Condition




Problem Solving with Decisions                                *Property of STI
                                                                Page 39 of 40
Data Structures and Algorithms




            The Decision
            Logic Structure

               Final Flowchart




Problem Solving with Decisions                *Property of STI
                                                Page 40 of 40

More Related Content

What's hot

Jumps in Assembly Language.
Jumps in Assembly Language.Jumps in Assembly Language.
Jumps in Assembly Language.NA000000
 
Logic microoperations
Logic microoperationsLogic microoperations
Logic microoperationsNitesh Singh
 
digital logic design Chapter 2 boolean_algebra_&_logic_gates
digital logic design Chapter 2 boolean_algebra_&_logic_gatesdigital logic design Chapter 2 boolean_algebra_&_logic_gates
digital logic design Chapter 2 boolean_algebra_&_logic_gatesImran Waris
 
Digital Logic & Design (DLD) presentation
Digital Logic & Design (DLD) presentationDigital Logic & Design (DLD) presentation
Digital Logic & Design (DLD) presentationfoyez ahammad
 
Hexadecimal to octal conversion
Hexadecimal to octal conversionHexadecimal to octal conversion
Hexadecimal to octal conversionMukesh Tekwani
 
Unit 4 memory system
Unit 4   memory systemUnit 4   memory system
Unit 4 memory systemchidabdu
 
Lecture ascii and ebcdic codes
Lecture ascii and ebcdic codesLecture ascii and ebcdic codes
Lecture ascii and ebcdic codesYazdan Yousafzai
 
1 introduction to problem solving and programming
1 introduction to problem solving and programming1 introduction to problem solving and programming
1 introduction to problem solving and programmingRheigh Henley Calderon
 
Programming flowcharts for C Language
Programming flowcharts for C LanguageProgramming flowcharts for C Language
Programming flowcharts for C LanguageAryan Ajmer
 
Sequential Logic Circuits
Sequential Logic CircuitsSequential Logic Circuits
Sequential Logic CircuitsDilum Bandara
 
boolean algebra and logic simplification
boolean algebra and logic simplificationboolean algebra and logic simplification
boolean algebra and logic simplificationUnsa Shakir
 
Network devices (2)
Network devices (2)Network devices (2)
Network devices (2)Dhani Ahmad
 
3.Fixed-Floating Point.ppt
3.Fixed-Floating Point.ppt3.Fixed-Floating Point.ppt
3.Fixed-Floating Point.pptRavikumarR77
 

What's hot (20)

Jumps in Assembly Language.
Jumps in Assembly Language.Jumps in Assembly Language.
Jumps in Assembly Language.
 
Logic microoperations
Logic microoperationsLogic microoperations
Logic microoperations
 
Matlab Workshop Presentation
Matlab Workshop PresentationMatlab Workshop Presentation
Matlab Workshop Presentation
 
digital logic design Chapter 2 boolean_algebra_&_logic_gates
digital logic design Chapter 2 boolean_algebra_&_logic_gatesdigital logic design Chapter 2 boolean_algebra_&_logic_gates
digital logic design Chapter 2 boolean_algebra_&_logic_gates
 
Digital Logic & Design (DLD) presentation
Digital Logic & Design (DLD) presentationDigital Logic & Design (DLD) presentation
Digital Logic & Design (DLD) presentation
 
Hexadecimal to octal conversion
Hexadecimal to octal conversionHexadecimal to octal conversion
Hexadecimal to octal conversion
 
Unit 4 memory system
Unit 4   memory systemUnit 4   memory system
Unit 4 memory system
 
Unit 4-booth algorithm
Unit 4-booth algorithmUnit 4-booth algorithm
Unit 4-booth algorithm
 
Lecture ascii and ebcdic codes
Lecture ascii and ebcdic codesLecture ascii and ebcdic codes
Lecture ascii and ebcdic codes
 
1 introduction to problem solving and programming
1 introduction to problem solving and programming1 introduction to problem solving and programming
1 introduction to problem solving and programming
 
8086 Introduction
8086 Introduction8086 Introduction
8086 Introduction
 
Programming flowcharts for C Language
Programming flowcharts for C LanguageProgramming flowcharts for C Language
Programming flowcharts for C Language
 
Instruction set of 8086 Microprocessor
Instruction set of 8086 Microprocessor Instruction set of 8086 Microprocessor
Instruction set of 8086 Microprocessor
 
Sequential Logic Circuits
Sequential Logic CircuitsSequential Logic Circuits
Sequential Logic Circuits
 
Theory of computing
Theory of computingTheory of computing
Theory of computing
 
boolean algebra and logic simplification
boolean algebra and logic simplificationboolean algebra and logic simplification
boolean algebra and logic simplification
 
Instruction types
Instruction typesInstruction types
Instruction types
 
Boolean Algebra
Boolean AlgebraBoolean Algebra
Boolean Algebra
 
Network devices (2)
Network devices (2)Network devices (2)
Network devices (2)
 
3.Fixed-Floating Point.ppt
3.Fixed-Floating Point.ppt3.Fixed-Floating Point.ppt
3.Fixed-Floating Point.ppt
 

More from Rheigh Henley Calderon (20)

10 data structures
10 data structures10 data structures
10 data structures
 
9 processing arrays
9 processing arrays9 processing arrays
9 processing arrays
 
8 problem solving with the case logic structure
8 problem solving with the case logic structure8 problem solving with the case logic structure
8 problem solving with the case logic structure
 
7 problem solving with loops
7 problem solving with loops7 problem solving with loops
7 problem solving with loops
 
4 introduction to programming structure
4 introduction to programming structure4 introduction to programming structure
4 introduction to programming structure
 
3 programming concepts
3 programming concepts3 programming concepts
3 programming concepts
 
2 beginning problem solving concepts for the computer
2 beginning problem solving concepts for the computer2 beginning problem solving concepts for the computer
2 beginning problem solving concepts for the computer
 
9 technical support
9 technical support9 technical support
9 technical support
 
8 customer service
8 customer service8 customer service
8 customer service
 
7 laptop repair
7 laptop repair7 laptop repair
7 laptop repair
 
6 laptop basics
6 laptop basics6 laptop basics
6 laptop basics
 
5 pc maintenance
5 pc maintenance5 pc maintenance
5 pc maintenance
 
4 pc repair
4 pc repair4 pc repair
4 pc repair
 
3 pc upgrade
3 pc upgrade3 pc upgrade
3 pc upgrade
 
2 pc assembly
2 pc assembly2 pc assembly
2 pc assembly
 
1 hardware fundamentals
1 hardware fundamentals1 hardware fundamentals
1 hardware fundamentals
 
8 cyber crimes
8 cyber crimes8 cyber crimes
8 cyber crimes
 
7 computer ethics
7 computer ethics7 computer ethics
7 computer ethics
 
6 professional ethics
6 professional ethics6 professional ethics
6 professional ethics
 
5 business ethics
5 business ethics5 business ethics
5 business ethics
 

Recently uploaded

IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IES VE
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024SkyPlanner
 
Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Brian Pichman
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintMahmoud Rabie
 
Designing A Time bound resource download URL
Designing A Time bound resource download URLDesigning A Time bound resource download URL
Designing A Time bound resource download URLRuncy Oommen
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsSafe Software
 
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationUsing IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationIES VE
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureEric D. Schabell
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8DianaGray10
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Will Schroeder
 
Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioChristian Posta
 
Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfAijun Zhang
 
Building AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxBuilding AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxUdaiappa Ramachandran
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxMatsuo Lab
 
How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?IES VE
 
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDEADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDELiveplex
 
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaborationbruanjhuli
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Commit University
 

Recently uploaded (20)

IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024
 
201610817 - edge part1
201610817 - edge part1201610817 - edge part1
201610817 - edge part1
 
20150722 - AGV
20150722 - AGV20150722 - AGV
20150722 - AGV
 
Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership Blueprint
 
Designing A Time bound resource download URL
Designing A Time bound resource download URLDesigning A Time bound resource download URL
Designing A Time bound resource download URL
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
 
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationUsing IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability Adventure
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
 
Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and Istio
 
Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdf
 
Building AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxBuilding AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptx
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptx
 
How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?
 
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDEADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
 
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)
 

6 problem solving with decisions

  • 1. Data Structures and Algorithms The Decision Logic Structure Some examples of conditional expressions are as follows : 1. A < B (A and B are the same the data type) 2. X + 5 >=Z (X and Z are numeric data) 3. E < 5 or F > 10 (E and F are numeric data) 4. DATAOK (DATAOK is a logical datum) Problem Solving with Decisions *Property of STI Page 1 of 40
  • 2. Data Structures and Algorithms The Decision Logic Structure Multiple IF/THEN/ELSE There are three types of decision logic you will use to write algorithms for solutions consisting of more than one decision. These types of decision logic include: · Straight-through logic · Positive logic · Negative Logic Problem Solving with Decisions *Property of STI Page 2 of 40
  • 3. Data Structures and Algorithms The Decision Logic Structure @ Single Condition – Two Possible Actions or Sets of Actions Problem Solving with Decisions *Property of STI Page 3 of 40
  • 4. Data Structures and Algorithms The Decision Logic Structure Straight-through logic @ Means that all of the decisions are processed sequentially, one after the other. @ There is no ELSE part of the instruction; the FALSE branch always goes to the next decision, and the TRUE branch goes to the next decision after the instructions for the TRUE branch have been processed. Problem Solving with Decisions *Property of STI Page 4 of 40
  • 5. Data Structures and Algorithms The Decision Logic Structure Positive Logic @ Allows the flow of the processing to continue through the module instead of processing succeeding decisions, once the resultant of a decision is true. @ Whenever the resultant is FALSE (the ELSE part of the decision), another decision in the sequence is processed until the resultant is TRUE, or there are no more decisions to process. @ At that time, the FALSE branch processes the remaining instructions. Problem Solving with Decisions *Property of STI Page 5 of 40
  • 6. Data Structures and Algorithms The Decision Logic Structure Negative Logic @ similar to positive logic except that the flow of the processing continues through the module when the resultant of a decision is FALSE @ whenever the resultant is TRUE, another decision is processed until the resultant is FALSE, or there are no more decisions to process @ at that time, the TRUE branch processes the remaining instructions @ the hardest to use and understand Problem Solving with Decisions *Property of STI Page 6 of 40
  • 7. Data Structures and Algorithms The Decision Logic Structure Using Straight-through logic Problem: Find the amount to charge people of varying ages for a food ticket. When the person is under 16, the charge is P7; when the person is 65 or over, the charge is P5; all others are charged P10. The conditions are the following : AGE CHARGE AGE < 16 7 AGE >=16 and AGE < 65 10 AGE >=65 5 Problem Solving with Decisions *Property of STI Page 7 of 40
  • 8. Data Structures and Algorithms The Decision Logic Structure Solution : Algorithm Flowchart A IF AGE < 16 THEN T CHARGE = 7 IF T AGE < 16 IF AGE >= 16 AND AGE <65 THEN T CHARGE = 10 Charge = 7 IF AGE >= 65 F THEN T CHARGE = 5 IF AGE >= 16 T and AGE < 65 Charge = 10 F IF T AGE >= 65 Charge = 10 F B Problem Solving with Decisions *Property of STI Page 8 of 40
  • 9. Data Structures and Algorithms The Decision Logic Structure Problem: Change the value of X to 0 when X becomes greater than 100, and to change the value of Y to 0 when Y becomes greater than 250 Algorithm Flowchart A IF X < 100 THEN IF T T X = 10 X > 100 IF Y > 250 X=0 THEN T F Y=0 IF T Y > 250 Y=0 F B Problem Solving with Decisions *Property of STI Page 9 of 40
  • 10. Data Structures and Algorithms The Decision Logic Structure Using Positive Logic Problem: Find the amount to charge people of varying ages for a food ticket. When the person is under 16, the charge is P7; when the person is 65 or over, the charge is P5; all others are charged P10. The conditions are the following : Algorithm IF AGE <16 THEN CHARGE = 7 ELSE IF AGE < 65 THEN CHARGE = 10 ELSE CHARGE = 5 Problem Solving with Decisions *Property of STI Page 10 of 40
  • 11. Data Structures and Algorithms The Decision Logic Structure Flowchart A F IF T AGE < 16 F IF T AGE < 65 CHARGE = 7 CHARGE = 5 CHARGE = 10 B Problem Solving with Decisions *Property of STI Page 11 of 40
  • 12. Data Structures and Algorithms The Decision Logic Structure Problem: Calculate the commission rate for a salesperson, given the amount of sales. When the salesperson has sold less than or equal to 2,000 worth of goods, the commission is 2%. When the sales total is more than 2,000 and less than or equal to 4,000, the commission is 4%. When sales total is more than 4,000 and less than or equal to 6,000, the commission is 7%. When the person has sold more than 6,000 the commission is 10%. The conditions are the following: SALES COMMISSION <=2000 .02 2001 – 4000 .04 4001 – 6000 .07 > 6000 .10 Problem Solving with Decisions *Property of STI Page 12 of 40
  • 13. Data Structures and Algorithms The Decision Logic Structure Solution 1: Algorithm IF SALES <= 2000 THEN COMMISSION = .02 T ELSE IF SALES <= 4000 THEN COMMISSION = .04 T ELSE IF SALES <= 6000 THEN F T COMMISSION = .07 F ELSE F COMMISSION = .1 Problem Solving with Decisions *Property of STI Page 13 of 40
  • 14. Data Structures and Algorithms The Decision Logic Structure Solution 1: Flowchart A F T IF SALES <=2000 F T COMMISSION = IF .02 SALES <=4000 COMMISSION F IF T = .04 SALES <=6000 COMMISSION COMMISSION = .1 = .07 B Problem Solving with Decisions *Property of STI Page 14 of 40
  • 15. Data Structures and Algorithms The Decision Logic Structure Solution 1: Test 1. TEST FOR 3. TEST FOR SALES = 1500 SALES = 5500 IS SALES <= 2000 IS SALES <= 2000 TRUE FALSE COMMISSION = .02 IS SALES <= 4000 FALSE 2. TEST FOR IS SALES <= 6000 SALES = 3500 TRUE IS SALES <= 2000 COMMISSION = .07 FALSE IS SALES <= 4000 4. TEST FOR TRUE SALES = 7500 COMMISSION = .04 IS SALES <= 2000 FALSE IS SALES <= 4000 FALSE IS SALES <= 6000 TRUE COMMISSION = .1 Problem Solving with Decisions *Property of STI Page 15 of 40
  • 16. Data Structures and Algorithms The Decision Logic Structure Solution 2: Algorithm IF SALES > 6000 THEN COMMISSION = .1 T ELSE IF SALES > 4000 THEN COMMISSION = .07 T ELSE IF SALES > 2000 THEN F T COMMISSION = .04 F ELSE F COMMISSION = .02 Problem Solving with Decisions *Property of STI Page 16 of 40
  • 17. Data Structures and Algorithms The Decision Logic Structure Solution 2: Flowchart A F T IF SALES > 6000 F T COMMISSION = IF .1 SALES > 4000 COMMISSION F IF T = .07 SALES > 2000 COMMISSION COMMISSION = .02 = .04 B Problem Solving with Decisions *Property of STI Page 17 of 40
  • 18. Data Structures and Algorithms The Decision Logic Structure Solution 2: Test 1. SALES = 1500 3. SALES = 5500 IS SALES > 6000 IS SALES > 6000 FALSE FALSE IS SALES > 4000 IS SALES > 4000 FALSE TRUE IS SALES > 2000 COMMISSION = .07 FALSE COMMISSION = .02 2. SALES = 3500 4. SALES = 7500 IS SALES > 6000 IS SALES > 6000 FALSE TRUE IS SALES > 4000 COMMISSION = .1 FALSE IS SALES > 2000 TRUE COMMISSION = .04 Problem Solving with Decisions *Property of STI Page 18 of 40
  • 19. Data Structures and Algorithms The Decision Logic Structure Using Negative Logic @ Negative Logic is the hardest for most people to comprehend because they do not think in negative terms. @ In general when you use negative logic you are telling the computer to process another decision when the resultant condition is TRUE; @ If the resultant is FALSE, then the computer processes a consequent set of instructions and then continues processing the module. Problem Solving with Decisions *Property of STI Page 19 of 40
  • 20. Data Structures and Algorithms The Decision Logic Structure Negative Logic Solution 1: Algorithm IF AGE >= 16 THEN IF AGE >= 65 THEN CHARGE = 5 ELSE CHARGE = 10 ELSE CHARGE = 7 Problem Solving with Decisions *Property of STI Page 20 of 40
  • 21. Data Structures and Algorithms The Decision Logic Structure Negative Logic Solution 1: Flowchart A F T IF AGE >= 16 F T CHARGE = 7 IF AGE >= 16 CHARGE = 10 CHARGE = 5 B Problem Solving with Decisions *Property of STI Page 21 of 40
  • 22. Data Structures and Algorithms The Decision Logic Structure Negative Logic Solution 2: Algorithm IF SALES > 2000 THEN IF SALES > 4000 THEN IF SALES > 6000 THEN COMMISSION = .1 ELSE COMMISSION = .07 ELSE COMMISSION = .04 ELSE COMMISSION = .02 Problem Solving with Decisions *Property of STI Page 22 of 40
  • 23. Data Structures and Algorithms The Decision Logic Structure Negative Logic Solution 2: Flowchart A IF SALES > 2000 COMMISSION = .02 IF SALES > 4000 COMMISSION = .04 IF SALES > 6000 COMMISSION = COMMISSION = .07 .01 B Problem Solving with Decisions *Property of STI Page 23 of 40
  • 24. Data Structures and Algorithms The Decision Logic Structure Negative Logic Solution 2: TEST 1. SALES = 1500 3. SALES = 5500 IS SALES > 2000 IS SALES > 2000 FALSE TRUE COMMISSION = .02 IS SALES > 4000 TRUE 2. SALES = 3500 IS SALES > 6000 IS SALES > 2000 FALSE TRUE COMMISSION = .1 IS SALES > 4000 FALSE 4. SALES = 7500 COMMISSION = .04 IS SALES > 2000 TRUE IS SALES > 4000 TRUE IS SALES > 6000 TRUE COMMISSION = .1 Problem Solving with Decisions *Property of STI Page 24 of 40
  • 25. Data Structures and Algorithms The Decision Logic Structure Another Set-Up: Algorithm IF SALES <= 6000 THEN IF SALES <= 4000 THEN IF SALES <= 2000 THEN COMMISSION = .02 ELSE COMMISSION = .04 ELSE COMMISION = .07 ELSE COMMISSION = .1 Problem Solving with Decisions *Property of STI Page 25 of 40
  • 26. Data Structures and Algorithms The Decision Logic Structure Another Set-Up: Flowchart A F T IF SALES <= 6000 CHARGE = .1 F T IF SALES <= 4000 COMMISSION = .07 F IF T SALES <= 2000 COMMISSION = COMMISSION = .04 .02 B Problem Solving with Decisions *Property of STI Page 26 of 40
  • 27. Data Structures and Algorithms The Decision Logic Structure Another Set-Up: Test 1. SALES = 1500 3. SALES = 5500 IS SALES <= 6000 IS SALES <= 6000 TRUE TRUE IS SALES <= 4000 IS SALES <= 4000 TRUE FALSE IS SALES <= 2000 COMMISSION = .07 TRUE COMMISSION = .02 2. SALES = 3500 4. SALES = 7500 IS SALES <= 6000 IS SALES <= 6000 TRUE FALSE IS SALES <= 4000 COMMISSION = .1 TRUE IS SALES <= 2000 FALSE COMMISSION = .04 Problem Solving with Decisions *Property of STI Page 27 of 40
  • 28. Data Structures and Algorithms The Decision Logic Structure Logic Conversion To convert from positive logic to negative logic or vice versa, do the following : 1. Change all < to >= 2. Change all <= to > 3. Change all > to <= 4. Change all >= to < 5. Change all = to <> 6. Change all <> to = 7. Interchange all of the THEN set of instructions with the corresponding ELSE set of instructions. Problem Solving with Decisions *Property of STI Page 28 of 40
  • 29. Data Structures and Algorithms The Decision Logic Structure Conversion from Positive to Negative Logic Problem Solving with Decisions *Property of STI Page 29 of 40
  • 30. Data Structures and Algorithms The Decision Logic Structure Which Decision Logic? To analyze which type of decision logic would be most efficient for a particular solution, answer the following questions: 1. Which type would make the solution most readable? 2. Which type would make the solution the easiest to maintain or change? 3. Which would require the fewest test when you don’t know anything about the data? 4. Which would require the fewest test when you’re given some data? Problem Solving with Decisions *Property of STI Page 30 of 40
  • 31. Data Structures and Algorithms The Decision Logic Structure Four ways to Design a Set of Conditions Problem Solving with Decisions *Property of STI Page 31 of 40
  • 32. Data Structures and Algorithms The Decision Logic Structure Decision Tables A decision table consists of four parts: @ The conditions. @ The actions. @ The combinations of TRUE and FALSE for the conditions. @ The action to be taken or the consequences for each combination of conditions. The four steps to develop a flowchart from the decision table are : @ Draw all decisions in flowchart form. @ Compare the true and false sides of each decision, starting with the first one. @ Eliminate any decisions that have the same instructions on both the true and false sides, keeping the true consequence or action. @ Redraw the flowchart. Problem Solving with Decisions *Property of STI Page 32 of 40
  • 33. Data Structures and Algorithms The Decision Logic Structure Decision Table Format Problem Solving with Decisions *Property of STI Page 33 of 40
  • 34. Data Structures and Algorithms The Decision Logic Structure Problem Solving with Decisions *Property of STI Page 34 of 40
  • 35. Data Structures and Algorithms The Decision Logic Structure Elimination of Conditions Problem Solving with Decisions *Property of STI Page 35 of 40
  • 36. Data Structures and Algorithms The Decision Logic Structure Final Flowchart Problem Solving with Decisions *Property of STI Page 36 of 40
  • 37. Data Structures and Algorithms The Decision Logic Structure Decision Table Problem Solving with Decisions *Property of STI Page 37 of 40
  • 38. Data Structures and Algorithms The Decision Logic Structure Starting Flowchart Problem Solving with Decisions *Property of STI Page 38 of 40
  • 39. Data Structures and Algorithms The Decision Logic Structure Elimination of Condition Problem Solving with Decisions *Property of STI Page 39 of 40
  • 40. Data Structures and Algorithms The Decision Logic Structure Final Flowchart Problem Solving with Decisions *Property of STI Page 40 of 40