2.+Business+Information+Systems+ +algorithms
2.+Business+Information+Systems+ +algorithms
WPO
Academic year 2022 – 2023
Alessandro Marchese
Course overview (WPO’s):
1. Introduction
2. Basic concepts in programming
1. Input
2. Output
3. Operating systems
3. Algorithms
4. Programming with Python
1. Data types and operators
2. Data structures
3. Conditions and iterations (if, for and while loops)
4. Functions
5. Reading and writing files
6. Exercises (all of the above combined)
Overview
● Input → Algorithm/Program → Output
Basics
Course overview (WPO’s):
1. Introduction
2. Basic concepts in programming
1. Input
2. Output
3. Operating systems
3. Algorithms
4. Programming with Python
1. Data types and operators
2. Data structures
3. Conditions and iterations (if, for and while loops)
4. Functions
5. Reading and writing files
6. Exercises (all of the above combined)
Overview
Revisiting the concept of “algorithm”
Algorithms
Informal example: a recipe
Automating algorithms
Given algorithms are ordered and unambiguous,
they are very convenient for automating repetitive
and complex problems
Algorithms
Basic Figures - Flow chart :
- Process
- Input / Output I O
- Choice
- Comments
- Sub-process
(procedure)
Algorithms
Sequence, selection and iteration in Flow chart :
1. Sequence
An algorithm is a sequence of commands that are executed consecutively.
Algorithms
Sequence, selection and iteration in Flow chart :
2 types:
Type I: If … Then …
– If condition is met: execute what is defined by program after 'Then'
statement
– If condition is not met: do nothing concrete (= skip 'Then' statement)
Algorithms
Sequence, selection and iteration in Flow chart :
Type I: example
Algorithms
Sequence, selection and iteration in Flow chart :
When to use? When you want to run part of your program/algorithm only if
a certain condition is met and run another part of your program /
algorithm if the condition is not met
(Type III: Case = nested If’s = combination of several Type I or / and II)
Algorithms
Sequence, selection and iteration in Flow chart :
Algorithms
Sequence, selection and iteration in Flow chart :
"Please go to the store and buy a bottle of milk, and if they have eggs, bring
six.“
Consequence?
Algorithms
Sequence, selection and iteration in Flow chart :
I O
Algorithms
Sequence, selection and iteration in Flow chart :
3 types
Type I: While: Execute as long as the condition is met
Algorithms
Sequence, selection and iteration in Flow chart :
NOTE: Make sure that the set condition is not always true 🡺
stuck in repeat / loop
Consequence?
Algorithms
Sequence, selection and iteration in Flow chart :
3 types
Type II: Repeat: Execute until condition is met
Algorithms
Sequence, selection and iteration in Flow chart :
3 types
Type II: Repeat: Execute until condition is met
Algorithms
Sequence, selection and iteration in Flow chart :
Consequence?
Algorithms
Sequence, selection and iteration in Flow chart :
3 types
Type III: For: Execute x amount of times
When to use?
• If you want to run part of your
program/algorithm a specific number of times
• i.e. you know in advance how many times it
must be performed
Algorithms
Sequence, selection and iteration in Flow chart :
3 types
Type III: For: Execute x amount of times
Algorithms
Sequence, selection and iteration in Flow chart :
NOTE:
● If x is a fixed amount of times 🡺 no infinite loop is
possible
● If x gets changed during looping 🡺 infinite loop is
possible
● Forget to count 🡺 infinite loop
Do 10 push-ups but for every push-up you do you are going to do one more.
→ 10 becomes 11, then 12, then 13, …
Algorithms
Exercise 1
Use a flow chart to represent the program that determines the state of the weather based
on a criterion: the temperature. The user should first submit today's temperature (T) and
the program will give the following results:
Tip: nested if
Exercices
Potential solution exercise 1
O O
Exercices
Exercise 2
Exercise 2.1
Design a Flow Chart for the algorithm representing the sum of the first 5 natural numbers
(Consider 0 to be the first natural number).
Exercise 2.2
Also design a Flow Chart for the same algorithm, but ask for input from the user about the
amount of natural numbers the algorithm should sum / add up: if the user enters, e.g., 12,
the algorithm should display the sum of the first 12 natural numbers (Consider 0 to be the
first natural number).
Tips:
• while or repeat
• First define a ‘counter’ (= initialisation)
Exercices
Potential solution exercise 2.1
Exercices
Potential solution exercise 2.2
Exercices
Exercise 3
The country Economania has coins and notes of 1, 5, 10, 100 en 500 Econos.
In the National Bank of Economania, employees are trained to hand out as few coins and
notes as possible, i.e. they try to:
• use as much notes of 500 Econos as possible; then
• use as many notes of 100 Econos as possible; etc.
For example, if you want to give someone 468 Econos, you will give them four notes of
100, six notes of 10, one note of 5 and three coins of 1, for a total of 14 notes and coins.
Design a flow chart for the algorithm that calculates how many notes and coins
employees should spend for any amount.
Exercices
Potential solution exercise 3
Exercices
Exercise 4
** More info on how tax brackets work exactly on the next slide
Design a flow chart for the algorithm that calculates how much tax a resident has to pay
when he/she enters his/her taxable income.
Exercices
Exercise 4 – Background on tax brackets
The system of tax brackets means that taxable income is
divided into brackets. A certain tax rate is applied to each
bracket.
Suppose you have a taxable income of 127,000 Econos in
Econlandia, your tax will be calculated as follows:
• Income below 10.000 Econos = 10.000 * 0% = 0 Econo in
taxes
• Income between 10.000 and 30.000 Econos = 20.000 *
10% = 2.000 Econo in taxes
• Income between 30.000 and 100.000 Econos = 70.000 *
25% = 17.500 Econos in taxes
• Income above 100.000 Econos = 27.000 * 40% = 10.800
Econos in taxes
Total tax
= 0 + 2000 + 17.500 + 10.800 Econos
= 30.300 Econos
Exercices
Potential solution exercise 4 (continued on the next slide)
Exercices
Potential solution exercise 4
Exercices
Exercise 5 (Homework)
Design the algorithm using a flow chart that calculates the quotient of a natural number
consisting of 3 digits (= dividend) and a natural number of 2 digits (= divisor) (i.e., the flow
chart for a tail division).
The quotient must be an integer and your algorithm should also display the residual value.
Exercises
Exercise 5 (Homework) - Continued
Steps:
• Step 1 : Problem definition : input (dividend and divisor), output (quotient) and the
relationship.
• Step 2 : Solution strategy : Divide the main problem into smaller actions you can
solve. In this specific case, you need to write down in words the different actions
you need to perform for the execution of a long division from start to finish :
• Execute a long division (following the instructions in the assignment) and try
to identify every action you perform (in your mind) and write them down.
• Try to perceive every action you identify either as a statement, either as an
input or an output, either as a choice (in order to construct a selection or an
iteration) in the flow chart.
• If you cannot convert one of your actions into one of these basic stuctures,
you need to divide this action into smaller actions until you are able to do so.
• Step 3 : Convert the words you wrote down in step 2 into a flow chart.
Exercises
Potential solution exercise 5
Exercises
Potential solution exercise 5 - Continued
O
O
Exercises