Uploaded by tonny muhiya

Unit 1

advertisement
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
DEV1A01 — Development Software 1A
Unit 1 — Problem Solving, and Algorithms
Dr Abejide Ade-Ibijola, PhD (Wits)
Research Cluster on Formal Structures, Algorithms and Industrial Applications
Department of Applied Information Systems
School of Consumer Systems and Information Systems
College of Business and Economics
University of Johannesburg.
2019
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
1 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Content
1
Problem Solving
2
Algorithms
3
Algorithm Exercises
4
Flowcharts
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
2 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Problem Solving
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
3 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Problem Solving
Solving problems is the core of Computer Science or Information Technology.
Programmers must first understand how a human solves a problem, then
understand how to translate this “algorithm” into something a computer can do.
Finally how to “write” the specific syntax (required by a computer) to get the job
done.
It is sometimes the case that a machine will solve a problem in a completely
different way than a human.
Example : Iris recognition.
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
4 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Problem Solving Contd.
Computer Programmers are problem solvers.
In order to solve a problem on a computer you must :
Know how to represent the information (or data) describing the problem (Data
Structures).
Determine the steps to transform the information from one representation into
another (Algorithms).
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
5 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Information Representation
A computer, at heart, is really dumb.
It can only really know about a few things. Such as :
numbers, characters, booleans, and lists (called arrays) of these items. (These are
called data types).
Everything else must be “approximated” by combinations of these data types.
A good programmer will “encode” all the “facts” necessary to represent a problem
into variables.
There are “good ways” and “bad ways” to encode information.
Good ways allow the computer to easily ”compute” new information.
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
6 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
The Six Steps of Problem Solving
The problem solving process start with problem specification and ends with a
concrete (and correct) program.
Problem solving steps are :
1
2
3
4
5
6
Problem definition
Problem analysis
Algorithm development
Coding
Program testing and debugging
Documentation
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
7 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Step 1 — Problem Definition
Sometimes referred to as Problem Specification.
Associated questions are :
What should the computer program do ?
What specific tasks will it perform ?
What kind of data will it use, and where will it get its data from ?
What will be the output of the program ?
How will the program interact with the user ?
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
8 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Step 1 — Problem Definition Contd.
At this stage, we :
specify the problem — state the problem clearly and unambiguously.
gain a clear understanding of what is required for its solution.
Objective is to eliminate unimportant aspects and to focus on the root problem, and this
may not be easy as it sound.
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
9 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Step 2 — Problem Analysis Contd.
Involves analysing the problem.
Associated questions are :
what inputs will be needed ? That is, the data you have to work with,
what outputs are expected ? These are the desired results, and
what other additional requirements or constraints on the solution.
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
10 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Step 3 — Algorithm Development
Sometimes referred to as Algorithm Design.
Create an algorithm for the desired solution.
Write step-by-step procedure and verify that the algorithm solves the problem as
intended.
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
11 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Step 3 — Algorithm Development Contd.
The algorithm can be expressed as Pseudocode, a Textual Algorithm, a
Mathematical Algorithm, or a Flowchart.
A Pseudocode is an informal high-level description of the operating principle of a
computer program or an algorithm.
A Textual Algorithm is a narrative description of the flow and logic of the intended
program, written in plain language that expresses each step of an algorithm.
A Mathematical Algorithm is a Pseudocode or a Textual Algorithm that contains
mathematical notation, typically from set and matrix theory, mixed with the control
structures of a conventional programming language. Mathematical style
Pseudocode is sometimes referred to as pidgin code.
A Flowcharts is a graphical representation that uses graphic symbols and arrows
to express the algorithms.
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
12 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Step 3 — Algorithm Development Contd.
For simplicity, we will refer to all of these, casually, as Algorithms.
After you write the algorithm you must realize step-by-step simulation of the
computer execution of the algorithm in a so called Desk-check process (verifying
the algorithm)
Desk-checking is also known as Dry-Running.
Algorithm Sketch or Algorithm Fragments — incomplete algorithms (or sketches)
that show parts of a larger algorithm.
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
13 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Common Mathematical Symbols
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
14 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Step 4 — Coding
Also referred to as Programming
Coding is the process of translating the algorithm into the syntax of any given
programming language.
You must convert each step into one or more statements in a programming
language.
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
15 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Step 5 — Testing and Debugging
Testing means running the program, executing all its instructions/functions, and
testing the logic by entering sample data to check the output.
Debugging is the process of finding and correcting program code mistakes (i.e.
Bugs).
Bug/Error types :
Syntax errors : Errors in the grammar of the programming language.
Semantic errors : Errors in the logic of the code.
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
16 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Step 6 — Documentation
Technical Documentation : Notes on how the software was written.
User Documentation : Notes on how to operate the software, and its functions.
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
17 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Algorithms
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
18 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Algorithms — An Overview
An algorithm is a set of specific steps to solve a problem.
Recall the students’ introduction algorithm ?
Think of it this way :
Game is a store, just like PnP, Woolworth, etc.
If you were to tell your friend how to get to Game and where to find the TV section at
Game : You will have to tell them : what transportation means are possible, what time of
the day Game is opened, where to find Game, which of the floors TV section is, and
perhaps, the description of the TV.
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
19 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Everyday-life Algorithms : Strategies
Example — Everyday-life Algorithms
How to run a country : Cabinet selection, shuffle and reshuffles. Tax rates
decisions.
How to win an election : Only two knights, but eight pawns.
How to argue : Oscar’s case.
How to be a successful student — gave you algorithms in the previous class.
Example — Algorithms in Sport
Think of algorithms in games/sport.
Jose Mourinho against attacking opponents :
Defend-defend-defend-attack
Military : Attack-attack-attack-defend
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
20 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Algorithms Contd.
The core of what good programmers do is being able to define the steps
necessary to accomplish a goal.
Unfortunately, a computer, only knows a very restricted and limited set of possible
steps.
For example a computer can add two numbers. But if you want to find the average
of two numbers, this is beyond the basic capabilities of a computer.
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
21 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Algorithms Contd.
Algorithm — Find the Average of Two Numbers (Sketch)
First: Add the two numbers and save this result in a variable
Then: Divide this new number by the number two, and save this result
in a variable.
Finally: provide this number to the rest of the program (or print it
for the user).
Exercise : Extend this algorithm to multiply two numbers.
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
22 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Algorithm — A Formal Definition
An algorithm is any well-defined computational procedure that takes some value,
or set of values, as input and produces some value, or set of values, as output.
An algorithm is thus a sequence of computational steps that transform the input
into the output.
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
23 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Qualities of a Good Algorithm
Inputs and outputs should be defined precisely.
Each steps in algorithm should be clear and unambiguous.
Algorithm should be the most effective among many different ways to solve a
problem.
An algorithm should NOT have computer code. Instead, the algorithm should be
written in such a way that, it can be used in similar programming languages.
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
24 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Notations for Writing an Algorithm
Numbering the steps (1,2,3, . . . )
Sub task numbering (1.1, 1.2, 1.3, . . . )
Keywords : OUTPUT/DISPLAY, INPUT/READ, IF-THEN, SET, etc.
Displaying result : OUTPUT
Finding out data about the problem : READ
Selecting conditions : IF-THEN
Assignment statement : SET variable = expr | value
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
25 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Variables
Variables are temporary memory locations.
The Rules
Variables names must start with a letter or an underscore, such as :
_underscore
underscore_
The remainder of your variable name may consist of letters, numbers and
underscores.
password1
n00b
un_der_scores
Names are case sensitive.
case_sensitive, CASE_SENSITIVE, and Case_Sensitive are each a different variable.
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
26 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Variable Naming Conventions
Readability is very important. Which of the following is easiest to read ?
first_year_folks
firstyearfolks
firstYearFolks
This is almost like hash-tagging #Twitter #Instagram
Descriptive names are very useful. If you are writing an algorithm or a program that
adds up all of the students in a class, which do you think is the better variable name ?
cool_uj_dudes
total_class_count
Avoid using the lowercase letter ‘l’ (L), uppercase ‘O’, and uppercase ‘I’. Why ?
Because the ‘l’ and the ‘I’ look a lot like each other and the number 1. And ‘O’ looks a
lot like ‘0’.
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
27 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Operators for Writing an Algorithm
Arithmetic Operators : +, − , /, *, ∧, mod, sqrt(), exp(), etc
Logical Operators : AND, OR, NOT
Relational Operators : <, <=, >, >=, ==, <>
String Operators : Concat, IndexOf, Contains, etc
Examples
CONCAT("I " , " am " , " Superman")
"JIDE".Contains("I") = true
"DR JIDE".Contains("DOCTOR") = false
"JIDE".IndexOf("E") = 3
"JAMES".IndexOf("I") = -1
"AVENGERS : AGE OF ULTRON".IndexOf("A") = ?
"OUR PERFECT WEDDING".IndexOf("W") = ?
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
28 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Further Notations : IF-THEN
Syntax
IF (logical condition(s)) THEN
Statement(s)
END IF
Example
IF (a > b) THEN
DISPLAY “a is greater than b”
END IF
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
29 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
IF-THEN-ELSE
Syntax
IF (logical condition(s)) THEN
Statement block 1
ELSE
Statement block 2
END IF
Example
IF (a > b) THEN
DISPLAY “a is greater than b”
ELSE
DISPLAY “a is not greater than b”
END IF
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
30 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Example (Worked in Class)
Write an algorithmic fragment that decides if a variable called “age” is 18 or above.
If yes, it should display that the user can vote. Else, it should display otherwise.
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
31 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
IF-THEN-ELSEIF
Syntax
IF (logical condition 1) THEN
Statement block 1
ELSEIF (logical condition 2) THEN
Statement block 2
ELSEIF (logical condition 3) THEN
Statement block 3
.
.
ELSEIF (logical condition n - 1) THEN
Statement block n - 1
ELSE
Statement block n
ENDIF
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
32 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
IF-THEN-ELSEIF (Contd.)
Example
IF (a > b) THEN
DISPLAY “a is greater than b”
ELSEIF (b > a) THEN
DISPLAY “b is greater than a”
ELSE
DISPLAY “a and b are equal”
ENDIF
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
33 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Example (Worked in Class)
Write an algorithmic fragment that decides the grade of a student based on their
mark. Assume the following :
75 to 100 : A
60 to 74 : B
50 to 59 : C
0 to 49 : F
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
34 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Looping
A loop is an algorithmic or code fragment that may be executed more than once.
Loop Types :
1
FOR LOOPS
2
DO LOOPS
3
WHILE LOOPS
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
35 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
FOR-Loop
Syntax
FOR variable = initial TO final STEP [steplength]
Statement to be repeated
END FOR
Example
FOR i = 1 TO 10 STEP 1
DISPLAY i
END FOR
FOR j = 1 TO 10 STEP 2
DISPLAY j
END FOR
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
36 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
FOR-Loop Contd.
Example
FOR num = 16 TO 32 STEP 4
DISPLAY num
END FOR
FOR k = 5 TO 10 STEP 5
DISPLAY k * 2
END FOR
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
37 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
FOR-Loop (Exercise)
What is the output of the following algorithmic fragment ?
Exercise — FOR-Loops
FOR k = -3 TO 15 STEP 5
DISPLAY k + 2
END FOR
FOR p = -1 TO -20 STEP -7
DISPLAY (-1) * p
END FOR
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
38 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Ungraded Assignment (Pick One)
Write an algorithm fragment (using a FOR loop) to display all even numbers
between 1 and 100.
Do the same for multiples of 3, between 1 and 100.
Write an algorithm fragment to display 1 to 20 in reverse.
Write an algorithm fragment to display the first 50 terms of the
alternating number line of even numbers. That is : -2, 4, -6, 8, . . .
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
39 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
WHILE and DO Loops
Syntaxes
WHILE (logical condition)
Statement block
END WHILE
DO
Statement block
UNTIL (logical condition)
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
40 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
WHILE Loops (Examples)
Example
x=3
WHILE (x >= 1)
DISPLAY x
x=x-2
END WHILE
What does this fragment display ?
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
41 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
WHILE Loops (Examples)
Example
a=2
WHILE (a <= 12)
DISPLAY a
a=a+2
END WHILE
What does this fragment display ?
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
42 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
DO Loops (Examples)
Example
i=8
DO
DISPLAY “2019 here we go”
LOOP UNTIL (i = 1)
What does this fragment display ? Is there a problem here ?
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
43 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
DO Loops (MORE Examples)
i=3
DO
i=3
DO
DISPLAY i + 2
LOOP UNTIL (i = 10)
i=i+2
LOOP UNTIL (i = 10)
a = true
WHILE (a = true)
a = false
DISPLAY "There is nothing to be confused about :)"
END WHILE
What does this fragments display ?
Is there a problem here ?
Dr Abejide Ade-Ibijola, PhD (Wits)
c = 12
DO
c=c-4
DISPLAY c
LOOP UNTIL (c <= 0)
DEV1A01
2019
44 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Putting an Algorithm Together
Starting an algorithm : START
Ending an algorithm : STOP
Request for data : READ
Selection : IF-THEN, ELSE, ELSE-IF
Looping : FOR, WHILE, DO
Displaying results : DISPLAY or PRINT
Best practices : line numbers, indentation, good variable naming, etc.
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
45 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Algorithm Exercises
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
46 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Full Algorithm Examples (Worked in Class)
Write an algorithm that :
calculate the average of two numbers
adds two numbers together (extend
this to multiply)
calculate the square of a number
determines if a user is old enough to
vote
displays 1 to 10
displays 40 to 50 with a do loop
displays 1 to n (n should be entered by
the user, and it is a number greater
than 1).
displays 1 to n (n should be entered by
the user, and it can be any integer on
the number line).
reads two numbers and determines
the largest of the two.
calculates the absolute of a value
calculates the root of a quadratic
equation
calculates the hypotenuse of a
right-angled triangle
calculate the area of a circle
calculates sum of n numbers
convert Fahrenheit to Celsius
calculates average of n numbers
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
47 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
More Examples (Worked Together in Class)
Write an algorithm that reads in two fractions of the form :
sum of these fractions.
x
,
y
and calculate the
Further thoughts : what if we have three fractions ?
How about n-fractions ?
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
48 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
More Algorithms (Solved in Class)
Mathematical :
Root of Quadratic Equations with imaginary roots.
Simple Interest.
The Factorial problem.
The Fibonacci problem.
Write an algorithm to determine the largest of three numbers.
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
49 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Nested Constructs
The constructs can be embedded within each other, and this is made clear by use
of indentation.
Nested constructs should be clearly indented from their surrounding constructs.
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
50 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Nesting of Loops
Write an algorithm to display a 4x4 box of stars.
Write an algorithm to display the multiplication table.
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
51 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Overtime Determination Algorithm
Write an algorithm that reads the number of hours worked by an employee.
If the hours worked is more than 8.
The algorithm should calculate the compensation the employee will receive given
that R80 is paid for every extra hour worked.
If no extra hours worked, the pay of the employee should be R100 per hour
worked.
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
52 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Example (Progression Algorithm)
Write an algorithm that adds numbers entered by the user together until the sum of all
numbers is more than 1000.
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
53 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Case
A CASE construct indicates a multi-way branch based on conditions that are
mutually exclusive. Four keywords, CASE, OF, OTHERS, and ENDCASE, and
conditions are used to indicate the various alternatives. The syntax form is :
CASE expression OF
condition 1 : sequence 1
condition 2 : sequence 2
...
condition n : sequence n
OTHERS :
default sequence
ENDCASE
Dr Abejide Ade-Ibijola, PhD (Wits)
The OTHERS clause with its default
sequence is optional. Conditions are
normally numbers or characters
indicating the value of "expression", but
they can be English statements or some
other notation that specifies the
condition under which the given
sequence is to be performed. A certain
sequence may be associated with more
than one condition.
DEV1A01
2019
54 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Example (Titles)
Exercise : Add more conditions and sequences to this example for the “Prof”
title, and other titles you can think of.
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
55 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Example (Grade Point)
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
56 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Exercises
Use the case structure to design an algorithm that determines the grading system
at the University of Johannesburg. That is ; 75-100 (A), . . .
Premier League Table : determine points earned by a team given the match result
text : “win”, “draw” or “loss”.
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
57 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Flowcharts
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
58 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Flowcharting
A diagrammatic representation of an algorithm.
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
59 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Common Flowchart Symbols
The process symbol represents a process, action, or
function. It’s the most widely-used symbol in
flowcharting.
The document symbol represents the input or output
of a document. Examples of input are receiving a
report, email, or order. Examples of output are
generating a presentation, memo, or letter.
The decision symbol indicates a question to be
answered-usually yes/no or true/false. The flowchart
path may splinter into different branches depending on
the answer.
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
60 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Common Flowchart Symbols
The connector symbol connects separate elements
across one page. It’s usually used within complex
charts.
The off-page connector (also known as the off-page
link) symbol connects separate elements across
multiple pages. It is frequently used within complex
charts. The page number is sometimes placed on the
shape for easy reference.
The Input/Output Symbol represents data that is
available for input or output.
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
61 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Common Flowchart Symbols
The comment symbol, or note symbol, adds needed
explanation or comment. It may be connected by a
dashed line to the relevant section of the flowchart.
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
62 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Other Flowchart Symbols
The stored data symbol represents data housed on a storage
device.
The summing junction symbol sums the input of several
converging paths.
The start/end symbol represents the start points, end points,
and potential outcomes of a path.
The predefined process symbol indicates a complicated
process or operation that is well-known or defined elsewhere.
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
63 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Other Flowchart Symbols
The internal storage symbol represents data stored in
random-access memory (RAM).
The manual input symbol represents the manual input
of data into a computer, usually through a keyboard.
The manual operation symbol indicates a step that
must be done manually, not automatically.
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
64 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Other Flowchart Symbols
The merge symbol combines multiple paths.
The multiple documents symbol represents multiple
documents or reports.
The preparation symbol differentiates between steps
that prepare for work and steps that actually do work.
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
65 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Example
Sum two numbers
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
66 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Examples
Determine if
temperature entered by
user is below or above
freezing point
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
67 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
Exercise
Draw a flowchart for the factorial problem.
Draw flowcharts for the previous algorithms discussed in this Unit.
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
68 / 69
Problem Solving
Algorithms
Algorithm Exercises
Flowcharts
End of Unit 1
Ready to code ?
Dr Abejide Ade-Ibijola, PhD (Wits)
DEV1A01
2019
69 / 69
Download