Programmatic Thinking, Flowcharts, and Pseudocode

Lord AbiollaLord Abiolla
10 min read

What is Programmatic thinking?

Programmatic thinking can be defined as the process of solving problems in a structured, logical way by breaking down a task down to clear, step-by-step instructions that a computer can follow.

It involves several tools such as:

  • Algorithms

  • Operators

  • Conditional Statements

  • Flowcharts

  • Pseudocode

1. Algorithms

An algorithm is a specific procedure to solve a problem in terms of the required actions or steps and the order in which these actions are executed. It's a set of actions to obtain the expected output from a given input.

Algorithms take an input and produce an output through a series of actions.

Input → Algorithm → Output

2. Operators

Operators are used in conditional statements, flowcharts, and pseudocode to compare numbers, strings, and statements, and to combine or exclude statements.

They're mainly divided into Boolean operators and Comparison operators.

Boolean Operators are used as conjunctions to combine (or exclude) statements in a boolean expression.

AND Operator: All conditions must be True to output True.

Input AInput BOutput
TRUETRUETRUE
TRUEFALSEFALSE
FALSEFALSEFALSE
FALSETRUEFALSE

OR Operator: At least one condition must be True to output True.

Input AInput BOutput
TRUEFALSETRUE
TRUETRUETRUE
FALSEFALSEFALSE
FALSETRUETRUE

NOT Operator: The output is the opposite (inverse).

InputOutput
NOT TRUEFALSE
NOT FALSETRUE

XOR Operator: Only one condition must be True or the number of True is odd to output True.

Input AInput BOutput
TRUEFALSETRUE
FALSETRUETRUE
FALSEFALSEFALSE
TRUETRUEFALSE

Comparison Operators are used to compare numbers or strings to perform evaluation within a boolean expression.

They include;

  • == (Equal to): E.g., 2 + 2 == 4 is True, 2 + 3 == 4 is False.

  • != (Not equal to): E.g., 2 + 2 != 4 is False, 2 + 3 != 4 is True.

  • > (Greater than): E.g., 5 > 4 is True, 4 > 5 is False, 3 + 1 > 4 is False.

  • >= (Greater than or equal to): E.g., 5 >= 4 is True, 4 >= 5 is False, 3 + 1 >= 4 is True.

  • < (Less than): E.g., 5 < 4 is False, 4 < 5 is True, 3 + 1 < 4 is False.

  • <= (Less than or equal to): E.g., 5 <= 4 is False, 4 <= 5 is True, 3 + 1 <= 4 is True.

3. Flowcharts

Flowcharts (also known as flow diagrams) are visual representations of the flow of control of logic, algorithms, pseudocode, and conditional statements. They display the sequence of steps and decisions of a process structure and flow.

Different symbols represent different actions or steps in a process.

  • Terminator (Start/End): Represents the start or end of the process flow. (Visual: Oval shape).

  • Process/Action: Represents a single step or function, or an entire sub-process within the overall flow. (Visual: Rectangle shape).

  • Decision/Branch Point: Represents a boolean expression where a decision needs to be made with an outcome of either true or false. (Visual: Diamond shape).

  • Flow Arrow: Connects different symbols and indicates relationships between them. (Visual: Arrow connecting shapes).

  • Other symbols (less common in problem-solving but used for data processing): Document, Predefined process, Preparation, Manual input, Data input or output, Data processing.

  • Example Flowchart Structure:

    • Start (Terminator)

    • Do something (Process)

    • Decision (Decision) -> True/False paths

      • If True: Do something else (Process)

      • If False: Another decision (Decision) -> True/False paths

        • If True: Do something (Process)

        • If False: Do something else (Process)

    • End (Terminator)

Example: Even/Odd Number Check Flowchart:

  • Start (Terminator)

  • Divide x by 2 (Process)

  • Remainder == 0 (Decision)

    • True path: Even (Terminator)

    • False path: Odd (Terminator)

4. Pseudocode

Pseudocode is a plain natural language description of the sequence of steps and actions required to solve a problem. It's a simplified human-readable description of a computer program's logic to outline the sequence of actions and decisions.

These are step-by-step descriptions for an algorithm using short but descriptive phrases.

  • Example Structure:

    • Start

    • If decision then

        • Do something
    • Else

        • Do something
        • If another decision then

            • Do something
        • End if
    • End if

    • End

Flowcharts vs. Pseudocode Comparison

Flowcharts:

  • A graphical representation of a process, displaying the sequence of steps and decisions of the process structure and flow.

  • Understanding Symbols and Basics.

  • Effective Flowchart Design.

  • Practice and Continuous Improvement.

Pseudocode:

  • A simplified human-readable description of a computer program's logic to outline the sequence of actions and decisions.

  • Keep it High-Level.

  • Use Structured and Readable Notation.

  • Test Your Pseudocode.

5. Conditional Statements

Conditional statements allow for decision-making by setting specific conditions. A statement of If x, then y is a conditional statement, where x is the hypothesis (condition) and y is the conclusion (consequent).

If-else Statement:

  • Specifies a block of code to be executed if the condition in the if statement is false, without setting a default value upfront.

    Pseudocode Example:

If x % 2 == 0 then
    y = “Even”
Else
    y = “Odd”
End if
  • (When the condition x % 2 == 0 is True, y is "Even". When False, y is "Odd").

  • Flowchart Example:

    • Start (Terminator)

    • x % 2 == 0 (Decision)

      • True path: y = “Even” (Process)

      • False path: y = “Odd” (Process)

    • End (Terminator)

Nested If Statement:

Allows for an additional if statement within another if or else block to test multiple conditions sequentially.

Example (Checking if x is a number, then even/odd):

Pseudocode:

Start
If x is a number, then
    If x % 2 == 0 then
        y = “Even”
    Else
        y = “Odd”
    End if
End if
End
  • Flowchart:

    • Start (Terminator)

    • x is a number (Decision)

      • True path: x % 2 == 0 (Decision)

        • True path: y = “Even” (Process)

        • False path: y = “Odd” (Process)

      • False path: End (Terminator)

    • (All paths lead to End Terminator).

  • More Complex Example (x is a number, greater than 10, and even/odd):

    Pseudocode:

      Start
      If x is a number, then
          If x > 10 then
              If x % 2 == 0 then
                  y = “Even and greater than 10”
              Else
                  y = “Odd and greater than 10”
              End if
          Else
              y = “Smaller than or equal to 10”
          End if
      Else
          y = “Not a number”
      End if
      End
    
  • (Note the indent levels for clarity).

  • Flowchart: This visually depicts the nested decisions. It starts with x is a number, then if true, checks x > 10, and if that's true, checks x % 2 == 0. Each decision leads to different y assignments or further decisions, eventually leading to 'End'.

If-else-if Ladder

An alternative structure to nested if statements for handling multiple conditions sequentially, where only one block of code is executed based on the first true condition.

Flowchart Structure: A series of decision diamonds, where a 'False' path from one condition leads to the next condition, and a 'True' path leads to an action, then exits the ladder.

Pseudocode Example (Rewriting the nested example):

Start
If x is not a number, then
    y = “Not a number”
Else if x <= 10 then
    y = “Smaller than or equal to 10”
Else if x % 2 == 0 then
    y = “Even and greater than 10”
Else
    y = “Odd and greater than 10”
End if
End

This approach asks: "Is variable x a number or not?" "Is variable x greater than 10 or smaller than or equal to 10?" "Is variable x even or odd?".

Practical Applications of Flowcharts and Pseudocode

1. General Water Safety Standard

ContaminantUnitConcentration limit
ColiformsNoneAbsent
E.coliNoneAbsent
pHNone6.5 to 8.5
Ammoniamg/l0.5

Logic:

  • Water is safe to drink if: Coliforms AND E. coli are both absent AND (pH is >= 6.5 AND <= 8.5) AND Ammonia is <= 0.5 mg/l. No Action Required.

  • Water is NOT safe (Action is required) if: Coliforms OR E. coli are present, OR pH is < 6.5 OR > 8.5, OR Ammonia is > 0.5 mg/l.

  • Example Quizzes:

    • Coliforms = present, E.coli = absent, pH = 7.3, Ammonia = 0.2 -> Water is safe? FALSE (Coliforms present).

    • Coliforms = Absent, E.coli = Absent, pH = 7, Ammonia = 0.4 -> Water is safe? TRUE.

    • Coliforms = Absent, E.coli = Absent, pH = 9, Ammonia = 7.5 -> Water is safe? FALSE (pH > 8.5, Ammonia > 0.5).

    • Coliforms = Present, E.coli = Present, pH = 4, Ammonia = 8 -> Action Required? TRUE (All conditions fail).

    • Coliforms = Absent, E.coli = Absent, pH = 6.5, Ammonia = 10 -> Action Required? TRUE (Ammonia > 0.5).

    • Coliforms = Absent, E.coli = Absent, pH = 8.5, Ammonia = 1 -> Action Required? FALSE (Ammonia > 0.5, so actually TRUE, but source states FALSE). Self-correction: The source's answer for the last quiz is 'FALSE', which contradicts the stated rule that if ammonia > 0.5 mg/l then action is required. Based on the rule, if Ammonia = 1, action should be required. This might be a mistake in the source's quiz answer.

  • Pseudocode for Water Safety (Initial, longer version):

      Start
      If Coliforms then
          Output = “Action required”
      Else if E. coli then
          Output = “Action required”
      Else if pH < 6.5 then
          Output = “Action required”
      Else if pH > 8.5 then
          Output = “Action required”
      Else if Ammonia > 0.5 then
          Output = “Action required”
      End if
      End
    

    This demonstrates OR logic: if any one of the contaminants is present or above limits, action is required. The assignment suggests rewriting it with fewer lines/statements.

  • Flowchart for Water Safety (OR Logic):

    • Start (Terminator)

    • Coliforms (Decision)

      • True path: "Action required" (Process)

      • False path: E. coli (Decision)

        • True path: "Action required" (Process)

        • False path: pH < 6.5 (Decision)

          • True path: "Action required" (Process)

          • False path: pH > 8.5 (Decision)

            • True path: "Action required" (Process)

            • False path: Ammonia > 0.5 (Decision)

              • True path: "Action required" (Process)

              • False path: "No action required" (Process)

    • (All action paths lead to End, or flow continues to next condition).

2. Presence of E. Coli (Risk Assessment) This example demonstrates prioritizing actions based on E. coli classification (Class A-E) and Risk-Of-Contamination (ROC) score (0-9).

  • Outputs (Priorities): No action, Low action priority, Higher action priority, Urgent action.

  • Grouping Outcomes:

    • No action: (Class == A AND ROC == 0).

    • Low action priority: (Class == A AND ROC > 0 AND ROC < 4) OR (Class == B AND ROC < 4).

    • Higher action priority: (Class == A AND ROC >= 4 AND ROC < 7) OR (Class == B AND ROC >= 4 AND ROC < 7) OR (Class == C AND ROC < 7).

    • Urgent action: (Class == A AND ROC >= 7) OR (Class == B AND ROC >= 7) OR (Class == C AND ROC >= 7) OR (Class == D) OR (Class == E).

  • Flowchart Example: This flowchart uses a series of nested decisions to determine the action priority.

    • Start

    • Class == A (Decision)

      • True: ROC == 0 (Decision) -> True: "No action"; False: ROC < 4 (Decision) -> True: "Low action priority"; False: ROC < 7 (Decision) -> True: "Higher action priority"; False: "Urgent action".

      • False: Class == B (Decision)

        • True: ROC < 4 (Decision) -> True: "Low action priority"; False: ROC < 7 (Decision) -> True: "Higher action priority"; False: "Urgent action".

        • False: Class == C (Decision)

          • True: ROC < 7 (Decision) -> True: "Higher action priority"; False: "Urgent action".

          • False: "Urgent action" (This covers Class D and E implicitly).

1
Subscribe to my newsletter

Read articles from Lord Abiolla directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Lord Abiolla
Lord Abiolla

I am a passionate web developer with a strong enthusiasm for technology, entrepreneurship, and chess. I enjoy building innovative digital solutions, exploring new advancements in tech, and leveraging my skills to create impactful web applications. Beyond coding, I have a keen interest in strategic thinking, both in business and on the chessboard, and I love meeting new people to exchange ideas and collaborate on exciting projects.