Flowcharting and Algorithms – Vocabulary

Flowcharting and Algorithms - Comprehensive Notes

  • Flowcharting and writing algorithms are foundational steps in program development

  • This set of notes covers definitions, activities, symbols, pseudocode, and practical examples from the provided transcript

  • Focus areas include: what programs are, how they are developed (problem understanding, planning, coding, compiling, testing, production), algorithm design, pseudocode, flowcharting, variables and operators, and common flowcharting patterns

Programs, Languages, and Programmers

  • Program: a set of detailed, step-by-step instructions that directs the computer what to do; a notation for expressing instructions to be carried out by a computer

  • Programs are written in a programming language: a set of rules that tells the computer what operations to perform

  • Person who creates programs: programmer

Activities involved in Programming

  • Understand the problem

  • Plan the logic

  • Code the program

  • Compile the program into machine language

  • Test the program

  • Put the program into production

Understanding the Problem
  • Programmer must understand the problem before writing code

  • Goal: satisfy the user’s need

  • Descriptions may be vague; user may not know exactly what they want

  • A good programmer acts as counsellor and detective to clarify requirements

Plan the Logic
  • Plan for the solution of the problem (ALGORITHMS)

  • Two common tools for planning: FLOWCHARTS and PSEUDOCODE

  • Involves writing steps in English (high level)

  • Do not worry about syntax yet; focus on sequence of events from input to output

Code the Program
  • There are over 400 programming languages

  • Languages have translators: compilers and interpreters

  • Examples: Pascal, C, C++, Visual Basic, Cobol, etc.

  • The coding phase focuses on correct syntax (commands, punctuation, spelling, etc.)

  • Actual construction of the source code

Compile the Program into Machine Language
  • Machine language is the only language a machine truly understands; consists of 0s and 1s

  • Compiler translates high-level language instructions into machine language

  • Compiler catches syntax errors

Test the Program
  • Execute and run the program with various test data to anticipate and fix errors before release

  • Error types: (1) syntactical or logical errors, (2) compile-time or run-time errors

  • Use sample data to verify proper operation

Put the Program into Production
  • Organization begins using the program

  • Train personnel to use it

  • Run with actual data

  • Test for user approval

Algorithm

  • A sequence of well-understood steps to do something

  • A set of instructions for a person to follow to accomplish a task

  • A sequence of instructions that tell how to solve a particular problem

  • Examples:

    • Directions for going to a place

    • Baking a chocolate cake

    • Computing income tax

    • Searching for a name in a telephone directory

Example: Prepare a Cup of Coffee
  • Step 1: Fill kettle with water

  • Step 2: Turn on stove

  • Step 3: Put kettle on stove

  • Step 4: If water is boiling, proceed to step 5; otherwise wait

  • Step 5: Turn off stove

  • Step 6: Fill mug with boiled water

  • Step 7: Put 1 tsp of coffee in mug

  • Step 8: With sugar, put 2 tsp of sugar in mug, otherwise proceed to step 9

  • Step 9: With milk, pour 1 tbsp of milk in mug, otherwise proceed to step 10

  • Step 10: Stir contents of mug

  • Step 11: (implied) Enjoy coffee

Characteristics of an Algorithm

  • Specify each step exactly: no ambiguity; clear instructions

  • Finite number of steps: algorithm must terminate with a stopping point

  • Output: algorithm must produce the correct result

Pseudocode and Flowcharts

  • Pseudocode: uses everyday language to describe the steps; abbreviated version of actual code

  • Looks more like a real program than a flowchart; helps focus on required steps

  • Advantage: can describe a program to nontechnical users and guide code writing

  • Pseudocode can describe a program in textual form that translates into actual code

  • Pseudocode is a textual presentation of a flowchart; close to natural language; control structures impose logic

  • May become part of program documentation; could be translated into a program

Example Algorithm: Total the Expense Receipts for the Month
  • Step 1: Total the expense receipts for the month

  • Step 2: Subtract the amount of the expense receipts from 1000

  • Step 3: If the remainder is > 0, return that amount to the company

  • Pseudocode (high level):

    • Begin

    • Get the Expenses

    • If Expenses < 1000 then

    • Subtract Expenses from 1000 (expenses-1000 = remainder)

    • Print "You Owe" and Remainder

    • Else

    • Print "You Owe Nothing"

  • End

Pseudocode for Determining Pass/Fail by Grade
  • Pseudocode: If student's grade is greater than or equal to 60, print "passed"; else print "failed"

  • Sample 1: Pseudocode

    • Begin

    • If Grade >= 60 then Print "passed" else Print "failed"

    • End

  • Sample 2: Class average of 10 students (pseudocode)

    • Initialize total to 0

    • Initialize grade counter to 1

    • While grade counter <= 10

    • Input the next grade

    • Add grade to total

    • Increment grade counter

    • Set class average to total / 10

    • Print class average

Flowcharting

What is Flowcharting?
  • A graphical representation of the logical steps that solve a problem

  • Used to understand the logic processing of data

  • Visualizes how statements in a program are interrelated

  • Time-consuming but beginner-friendly

  • Uses symbols and phrases to designate logic of problem solving

  • Defines the basic input, process, and output (IPO) function within a program

  • A diagram representing the logical sequence in which steps/operations are performed; a blueprint of the program

Types of Flowcharts
  • Program Flowcharts: depict the detailed logical flow of a process in a program

  • System Flowcharts: show the data flow from source to destination; divided into department or personnel functions; symbols represent documents and operations; highlights excessive information flow, data duplication, and delays

Basic Flowcharting Symbols (with common meanings)
  • Terminal block: Start/End (oval/rounded-rectangle shape)

  • Preparation/Initialization: Initial data setup or conditions (often shown as a hexagon on some diagrams; examples include SUM=0 or PRODUCT=0)

  • Input/Output: Parallelogram (reads data or prints data): e.g., Read A, Print A

  • Process/Processing: Rectangle (computations/assignments): e.g., Sum = A + B

  • Decision: Diamond (tests a condition; two possible paths: True/False)

  • On-page Connector: Small circle to connect flow within the same page

  • Off-page Connector: Pentagon (connexion to other pages)

  • Initialization symbol: used to denote setup of data or variables

  • Flow lines: arrows showing the sequence of steps

System Flowcharting Symbols (data processing view)
  • Data, Process, Decision, Document, Start/End, Direct Data, Stored Data, Internal, Manual Input, Storage, Predefined Process, Sequential Access Storage

Basic Flowcharting Examples and Conventions
  • Simple flow from input to processing to output

  • Input operation (Read, Print) are represented by parallelograms

  • Processing (arithmetic/assignment) shown in rectangles

  • Flow lines and terminal symbols indicate correct sequence

  • Example: Get number → Answer = number * 2 → Print Answer

Example Representation (Begin/End)
  • Begin

  • Get number

  • Answer = number * 2

  • Print Answer

  • End

  • Note: After designing the flowchart, choose the programming language to implement the flowchart code

Variables
  • What are variables? Memory locations whose content may vary/change

  • The ability of memory variables to change makes computing possible: one memory location can be reused with different values

  • Naming: variable names may differ by language (hyphens, underscores, etc.); some languages limit name length

  • Rules for naming variables:

    • Must be one word

    • May contain letters, numbers, hyphens, underscores

    • Must not start with a number

    • Must not contain a space

    • Should have meaningful names

  • Invalid variable name examples:

    • interest rate (space) → should be one word

    • rate! (special character) → invalid

    • xyxxx (meaningful but non-descriptive) → not ideal

    • #total (starts with a special character) → invalid

Types of Variables
  • Numeric Variables: hold numbers; may be integer/whole numbers or floating-point/decimal

  • Character/Text/String Variables: hold letters and punctuation; e.g., NAME = "WASHINGTON"

  • Logical/Boolean Variables: can be TRUE or FALSE

Arithmetic Operators and Statements
  • Addition (+), Subtraction (-), Multiplication (*), Division (/), Modulus (% )

  • A typical numeric statement:

    • leftvariable = leftvariable oparator right_operand(s)

    • Examples: ext{Sum} = A + B \

  • Example representations: x = x + 1; sum = a + b

Constants
  • A constant is a value that never changes during execution

  • Constants can be numeric, alphabetic, or other symbols

  • Like variables, constants can be named; memory location holds the constant value

  • During execution, the constant is referred to by its name; value cannot be changed

Relational Operators
  • Compare two values to determine their relationship

  • Examples and returns:

    • op1 > op2: true if op1 is greater than op2

    • op1 >= op2: true if op1 is greater than or equal to op2

    • op1 < op2: true if op1 is less than op2

    • op1 <= op2: true if op1 is less than or equal to op2

    • op1 == op2: true if op1 and op2 are equal

    • op1 != op2: true if op1 and op2 are not equal

Logical Operators (Boolean)
  • Used to express relationships between conditions

  • Operators:

    • cond1 and cond2: true if both conditions are true

    • cond1 or cond2: true if either condition is true

    • not cond: negation of cond

Flowcharting Examples

Example 1: Going to School
  • Start

  • Get in Car

  • Drive to School

  • Park Car

  • Walk to Class

  • Attend Class

  • End

  • If not going to class: Walk to Car, Get in Car, Drive Home, End

Example 2: Bath Flowchart
  • Start

  • Fill the bath with water

  • Get undressed

  • Get into bath

  • Wash

  • Get out of bath

  • Empty the bath water

  • Get dressed

  • End

Example 3: Enter 2 Numbers, Compute and Display Sum
  • Start

  • X = 0, Y = 0, Sum = 0

  • Enter X

  • Enter Y

  • Sum = X + Y

  • Print Sum

  • End

Example 4: Name and Age, Determine Young or Old
  • Start

  • Name = " ", age = 0

  • Enter Name, Age

  • If Age > 18? -> Yes: Print YOUNG or OLD accordingly

  • End

Practice: Flowchart and Algorithms for Common Tasks
  • Example: Draw a flowchart to accept and display a number; algorithm:

    • Step 1: Read in the value of N

    • Step 2: Print the value of N

    • Start → Read N → Print N → End

  • Example: Flowchart to compute and display the sum and product of two numbers; algorithm:

    • Step 1: Initialize Sum and Product to 0

    • Step 2: Read A and B

    • Step 3: Sum = A + B; Product = A * B

    • Step 4: Print Sum and Product

    • Start → Read A,B → Print Sum, Product → End

  • Example: Flowchart to convert Fahrenheit to Celsius; formula and algorithm:

    • Formula: C = rac{5}{9}igl(F - 32igr)</p></li><li><p>Algorithm:Step1:Celsius=0;Step2:ReadFahrenheit;Step3:ComputeCelsius;Step4:PrintCelsius</p></li></ul></li><li><p>Example:ComparetwonumbersAandBandprinthighervaluewithremark"Higher"</p><ul><li><p>Algorithm:Step1:ReadAandB;Step2:IfA>B,printAand"Higher";elseprintBand"Higher"</p></li></ul></li></ul><h5id="bdaeddc7−63b4−48c5−9e99−43e864fe4be1"data−toc−id="bdaeddc7−63b4−48c5−9e99−43e864fe4be1"collapsed="false"seolevelmigrated="true">MoreExamples(QuizandStudentDataHandling)</h5><ul><li><p>Example:Inputgradeofastudentanddeterminepass/fail</p><ul><li><p>IfGrade>=60→Passed;elseFailed</p></li><li><p>PrintName,Grade,andRemarks</p></li></ul></li><li><p>Example:Enterscoresforanumberofquizzesandaccumulatetotal</p><ul><li><p>Initializecounterandtotal;loopuntilcounterreachesthenumberofquizzes;inputscore;addtototal;incrementcounter;endwhencomplete</p></li></ul></li></ul><h4id="98e2d983−1585−49eb−b564−376b36c664d7"data−toc−id="98e2d983−1585−49eb−b564−376b36c664d7"collapsed="false"seolevelmigrated="true">Switch−CASEandStructuredProgramming</h4><h5id="ea3580f2−cb37−4467−b6ce−8ee75534efef"data−toc−id="ea3580f2−cb37−4467−b6ce−8ee75534efef"collapsed="false"seolevelmigrated="true">TheSwitch−CASEStructure</h5><ul><li><p>Acontrolstructurethatselectsamongmultiplediscretecases</p></li><li><p>Exampleimageshowsadecisionpathforclassandcorrespondingfees,demonstratinghowcasesmaptooutcomes</p></li><li><p>Rationale:simplifiesmulti−branchdecisions</p></li></ul><h5id="0cf28e00−dafa−49be−ba4d−cb64e7cb480a"data−toc−id="0cf28e00−dafa−49be−ba4d−cb64e7cb480a"collapsed="false"seolevelmigrated="true">ReasonsforStructuredProgramming</h5><ul><li><p>Clarity:structuredlogicscalesbetterasprogramsgrow</p></li><li><p>Professionalism:expectedtousestructureddesigns</p></li><li><p>Efficiency:allowsbuildingmoreefficientprogramsacrosslanguages</p></li><li><p>Modularity:divideintoreusableroutinesthatcanbeassembled</p></li></ul><h4id="e7016b6a−1f41−44e0−9c49−a3da8e356bc0"data−toc−id="e7016b6a−1f41−44e0−9c49−a3da8e356bc0"collapsed="false"seolevelmigrated="true">PracticalFlowchartingTasksandAlgorithms</h4><ul><li><p>Drawaflowchartthatacceptsanddisplaysanumber;equivalentalgorithm:</p><ul><li><p>Step1:ReadN</p></li><li><p>Step2:PrintN</p></li><li><p>Start→ReadN→PrintN→End</p></li></ul></li><li><p>Drawaflowchartthatcomputesanddisplayssumandproductoftwonumbers;algorithm:</p><ul><li><p>Step1:InitializeSum=0,Product=0</p></li><li><p>Step2:ReadA,B</p></li><li><p>Step3:Sum=A+B;Product=A×B</p></li><li><p>Step4:PrintSumandProduct</p></li><li><p>Start→ReadA,B→PrintSum,Product→End</p></li></ul></li><li><p>FlowcharttoconvertFahrenheittoCelsius(Celsiusformulaabove)andcorrespondingalgorithm</p></li><li><p>FlowcharttoinputAandB,compareandprintwhichishigherwithremark</p></li><li><p>Flowcharttoinputstudentnameandgrade,determinePassed/Failedandprintname,grade,andremark</p></li><li><p>Flowcharttoinputscoresforanumberofquizzesandaccumulatescores</p></li></ul><h4id="8d2648f7−abb3−47a5−99fb−9b1f98f0e55e"data−toc−id="8d2648f7−abb3−47a5−99fb−9b1f98f0e55e"collapsed="false"seolevelmigrated="true">SummaryofKeyConceptsandFormulas</h4><ul><li><p>Programvslanguagevsprogrammer</p></li><li><p>Algorithmasasequenceofunambiguousstepswithfiniteterminationandanoutput</p></li><li><p>Pseudocodeasabridgebetweennaturallanguageandactualcode</p></li><li><p>FlowchartsasgraphicalrepresentationsofIPO(Input−Process−Output)logic</p></li><li><p>Basicflowchartingsymbolsandtheirmeanings:Terminal,Initialization,Input/Output,Process,Decision,On−pageConnector,Off−pageConnector</p></li><li><p>Systemflowchartingaddsdataflow,documents,andstorageelements</p></li><li><p>Variables:memorylocationswithnames;rulesfornaming;types(Numeric,Text/String,Boolean)</p></li><li><p>Arithmeticoperators:</p><ul><li><p></p></li><li><p>Algorithm: Step 1: Celsius = 0; Step 2: Read Fahrenheit; Step 3: Compute Celsius; Step 4: Print Celsius</p></li></ul></li><li><p>Example: Compare two numbers A and B and print higher value with remark "Higher"</p><ul><li><p>Algorithm: Step 1: Read A and B; Step 2: If A > B, print A and "Higher"; else print B and "Higher"</p></li></ul></li></ul><h5 id="bdaeddc7-63b4-48c5-9e99-43e864fe4be1" data-toc-id="bdaeddc7-63b4-48c5-9e99-43e864fe4be1" collapsed="false" seolevelmigrated="true">More Examples (Quiz and Student Data Handling)</h5><ul><li><p>Example: Input grade of a student and determine pass/fail</p><ul><li><p>If Grade >= 60 → Passed; else Failed</p></li><li><p>Print Name, Grade, and Remarks</p></li></ul></li><li><p>Example: Enter scores for a number of quizzes and accumulate total</p><ul><li><p>Initialize counter and total; loop until counter reaches the number of quizzes; input score; add to total; increment counter; end when complete</p></li></ul></li></ul><h4 id="98e2d983-1585-49eb-b564-376b36c664d7" data-toc-id="98e2d983-1585-49eb-b564-376b36c664d7" collapsed="false" seolevelmigrated="true">Switch-CASE and Structured Programming</h4><h5 id="ea3580f2-cb37-4467-b6ce-8ee75534efef" data-toc-id="ea3580f2-cb37-4467-b6ce-8ee75534efef" collapsed="false" seolevelmigrated="true">The Switch-CASE Structure</h5><ul><li><p>A control structure that selects among multiple discrete cases</p></li><li><p>Example image shows a decision path for class and corresponding fees, demonstrating how cases map to outcomes</p></li><li><p>Rationale: simplifies multi-branch decisions</p></li></ul><h5 id="0cf28e00-dafa-49be-ba4d-cb64e7cb480a" data-toc-id="0cf28e00-dafa-49be-ba4d-cb64e7cb480a" collapsed="false" seolevelmigrated="true">Reasons for Structured Programming</h5><ul><li><p>Clarity: structured logic scales better as programs grow</p></li><li><p>Professionalism: expected to use structured designs</p></li><li><p>Efficiency: allows building more efficient programs across languages</p></li><li><p>Modularity: divide into reusable routines that can be assembled</p></li></ul><h4 id="e7016b6a-1f41-44e0-9c49-a3da8e356bc0" data-toc-id="e7016b6a-1f41-44e0-9c49-a3da8e356bc0" collapsed="false" seolevelmigrated="true">Practical Flowcharting Tasks and Algorithms</h4><ul><li><p>Draw a flowchart that accepts and displays a number; equivalent algorithm:</p><ul><li><p>Step 1: Read N</p></li><li><p>Step 2: Print N</p></li><li><p>Start → Read N → Print N → End</p></li></ul></li><li><p>Draw a flowchart that computes and displays sum and product of two numbers; algorithm:</p><ul><li><p>Step 1: Initialize Sum = 0, Product = 0</p></li><li><p>Step 2: Read A, B</p></li><li><p>Step 3: Sum = A + B; Product = A × B</p></li><li><p>Step 4: Print Sum and Product</p></li><li><p>Start → Read A,B → Print Sum, Product → End</p></li></ul></li><li><p>Flowchart to convert Fahrenheit to Celsius (Celsius formula above) and corresponding algorithm</p></li><li><p>Flowchart to input A and B, compare and print which is higher with remark</p></li><li><p>Flowchart to input student name and grade, determine Passed/Failed and print name, grade, and remark</p></li><li><p>Flowchart to input scores for a number of quizzes and accumulate scores</p></li></ul><h4 id="8d2648f7-abb3-47a5-99fb-9b1f98f0e55e" data-toc-id="8d2648f7-abb3-47a5-99fb-9b1f98f0e55e" collapsed="false" seolevelmigrated="true">Summary of Key Concepts and Formulas</h4><ul><li><p>Program vs language vs programmer</p></li><li><p>Algorithm as a sequence of unambiguous steps with finite termination and an output</p></li><li><p>Pseudocode as a bridge between natural language and actual code</p></li><li><p>Flowcharts as graphical representations of IPO (Input-Process-Output) logic</p></li><li><p>Basic flowcharting symbols and their meanings: Terminal, Initialization, Input/Output, Process, Decision, On-page Connector, Off-page Connector</p></li><li><p>System flowcharting adds data flow, documents, and storage elements</p></li><li><p>Variables: memory locations with names; rules for naming; types (Numeric, Text/String, Boolean)</p></li><li><p>Arithmetic operators:</p><ul><li><p>+,\, -, \, \, ackslash?, etc.(common:+,−,∗,/,(common: +, -, *, /, %)</p></li></ul></li><li><p>Constants: fixed values that do not change during execution</p></li><li><p>Relational operators: >, >=, <, <=, ==, !=</p></li><li><p>Logical/Boolean operators: and, or, not</p></li><li><p>Basic flowcharting patterns: Simple Sequence, Selection, Iteration, and Linking</p></li><li><p>Advantages and limitations of flowcharts</p></li><li><p>Structured programming principles: clarity, professionalism, efficiency, modularity</p></li></ul><h4 id="c0580d96-54cd-4fe9-a1d2-156ccaf30cb3" data-toc-id="c0580d96-54cd-4fe9-a1d2-156ccaf30cb3" collapsed="false" seolevelmigrated="true">Important Notation and Formulas</h4><ul><li><p>Celsius from Fahrenheit:</p><ul><li><p>C = rac{5}{9}igl(F - 32igr)</p></li></ul></li><li><p>SumandProductoftwonumbers:</p><ul><li><p></p></li></ul></li><li><p>Sum and Product of two numbers:</p><ul><li><p> ext{Sum} = A + B</p></li><li><p></p></li><li><p> ext{Product} = A imes B$$

  • Example logical condition checks:

    • If value X greater than Y: X > Y

    • If two conditions must both be true: cond1 \land cond2

    • If either condition is true: cond1 \lor cond2

    • Negation: \neg cond

Note: The above notes reproduce the major concepts, definitions, examples, and the common patterns and structures from the transcript. They are organized to function as a comprehensive study guide that mirrors the content presented in the slides, including both high-level ideas and specific step-by-step examples.