24dkd-ex-python-week1
24dkd-ex-python-week1
Python
Programming
MSc. Vo Hoang Thuy Tien
Course info
week date content
Grading
1 1/8/2025 Introduction
Exercises: 10% 2 1/15/2025 control flow
String Manipulation, Guess and Check,
3 1/22/2025
Approximations, Bisection
4 2/12/2025 Decomposition, Abstractions, Functions
5 2/19/2025 Tuples, Lists, Aliasing, Mutability, Cloning
6 2/26/2025 mid-semester exam
7 3/5/2025 Recursion & Dictionary
8 3/12/2025 Testing, Debugging, Exceptions, Assertions
9 3/19/2025 UNDERSTANDING PROGRAM EFFICIENCY
10 3/26/2025 Advance topic: Data analysis with pandas,numpy
11 4/2/2025 Advance topic: Visualization with Mathplot, Plotly
2
Algorithmic problem solving
Week 1
3
Algorithmic problem solving
Problem solving
Problem solving is the systematic approach to define the problem and creating
number of solutions.
The problem solving process starts with the problem specifications and ends with a
correct program.
4
Algorithmic problem solving
Problem solving techniques
Problem solving technique is a set of techniques that helps in providing logic for
solving a problem
5
Algorithmic problem solving
Problem solving techniques
1. Algorithm
6
Algorithmic problem solving
Problem solving techniques
1. Algorithm
The following are the primary factors that are often used to judge the quality of the algorithms.
Time – To execute a program, the computer system takes some amount of time. The
lesser is the time required, the better is the algorithm.
Memory – To execute a program, computer system takes some amount of memory
space. The lesser is the memory required, the better is the algorithm.
Accuracy – Multiple algorithms may provide suitable or correct solutions to a given
problem, some of these may provide more accurate results than others, and such algorithms
may be suitable
7
Algorithmic problem solving
Problem solving techniques
1. Algorithm
As algorithm is a part of the blue-print or plan for the computer program. An algorithm is
constructed using following blocks.
• Statements
• States
• Control flow
• Function
8
Algorithmic problem solving
Problem solving techniques
1. Algorithm
Statements are simple sentences written in algorithm for specific purpose. Statements may
consists of assignment statements, input/output statements, comment statements
Example:
• Read the value of ‘a’ //This is input statement
• Calculate c=a+b //This is assignment statement
• Print the value of c // This is output statement
Comment statements are given after // symbol, which is used to tell the purpose of the line
9
Algorithmic problem solving
Problem solving techniques
1. Algorithm
10
Algorithmic problem solving
Problem solving techniques
1. Algorithm
Control flow which is also stated as flow of control, determines what section of code is to run in
program at a given time. There are three types of flows, they are
1. Sequential control flow
2. Selection or Conditional control flow
3. Looping or repetition control flow
11
Algorithmic problem solving
Problem solving techniques
1. Algorithm
The name suggests the sequential control structure is used to perform the action one after
another. Only one step is executed once. The logic is top to bottom approach.
Example Description: To find the sum of two numbers.
Step 1. Start
Step 2. Read the value of ‘a’
Step 3. Read the value of ‘b’
Step 4. Calculate sum=a+b
Step 5. Print the sum of two number
Step 6. Stop 12
Algorithmic problem solving
Problem solving techniques
1. Notations of an algorithm
13
Algorithmic problem solving
Problem solving techniques
2. Notations of an algorithm: Pseudo code
14
Algorithmic problem solving
Problem solving techniques
2. Notations of an algorithm: Pseudo code
1. Only one statement per line. Statements represents single action is written on same line. For
example to read the input, all the inputs must be read using single statement.
2. Capitalized initial keywords. The keywords should be written in capital letters. Eg: READ, WRITE,
IF, ELSE, ENDIF, WHILE, REPEAT, UNTIL
3. Indent to show hierarchy. Indentation is a process of showing the boundaries of the structure.
4. End multi-line structures. Each structure must be ended properly, which provides more clarity.
5. Keep statements language independent.
6. Pesudocode must never written or use any syntax of any programming language
15
Algorithmic problem solving
Problem solving techniques
2. Notations of an algorithm: Pseudo code
Example 2: Example 4:
Pseudocode: Find the total and average of three subjects Pseudocode: Find greatest of two numbers
READ name, department, mark1, mark2, mark3 READ a, b
Total=mark1+mark2+mark3 IF a>b then
Average=Total/3 PRINT a is greater
WRITE name, department,mark1, mark2, mark3 ELSE
PRINT b is greater
ENDIF
17
Algorithmic problem solving
Problem solving techniques
2. Notations of an algorithm: Pseudo code
18
Algorithmic problem solving
Problem solving techniques
2. Notations of an algorithm: Flowchart
19
Algorithmic problem solving
Problem solving techniques
No Name of symboy Symbol Type Description
1 terminal symbol oval represent the start and stop of the program
Input/ Output
2 Parallelogram Denotes either input or output operation
symbol
1. In drawing a proper flowchart, all necessary requirements should be listed out in logical order.
2. The flow chart should be clear, neat and easy to follow. There should not be any room for
ambiguity in understanding the flowchart.
3. The usual directions of the flow of a procedure or system is from left to right or top to bottom.
Only one flow line should come out from a process symbol.
21
Algorithmic problem solving
Problem solving techniques
2. Notations of an algorithm: Flowchart
4. Only one flow line should enter a decision symbol, but two or three flow lines, one for each
possible answer, cap leave the decision symbol.
5. Only one flow line is used in conjunction with terminal symbol.
6. If flowchart becomes complex, it is better to use connector symbols to reduce the number of
flow lines.
7. Ensure that flowchart has logical start and stop.
22
Algorithmic problem solving
Problem solving techniques
2. Notations of an algorithm: Flowchart
Advantages of Flowchart
Communication: Flowcharts are better way of communicating the logic of the system.
Effective Analysis: With the help of flowchart, a problem can be analyzed in more effective way.
Proper Documentation: Flowcharts are used for good program documentation, which is needed
for various purposes.
Efficient Coding: The flowcharts act as a guide or blue print during the system analysis and
program development phase.
Systematic Testing and Debugging: The flowchart helps in testing and debugging the program
Efficient Program Maintenance: The maintenance of operating program becomes easy with the
help of flowchart. It helps the programmer to put efforts more efficiently on that part.
23
Algorithmic problem solving
Problem solving techniques
2. Notations of an algorithm: Flowchart
Disadvantages of Flowchart
Complex Logic: Sometimes, the program logic is quite complicated. In that case flowchart
becomes complex and difficult to use.
Alteration and Modification: If alterations are required the flowchart may require redrawing
completely.
Reproduction: As the flowchart symbols cannot be typed, reproduction becomes problematic.
24
Algorithmic problem solving
Problem solving techniques
2. Notations of an algorithm: Flowchart
Control Structures using flowcharts and Pseudocode
25
Algorithmic problem solving
Problem solving techniques
2. Notations of an algorithm: Flowchart
Control Structures using flowcharts and Pseudocode
26
Algorithmic problem solving
Exercises
1. Write an algorithm to find area of rectangle
27
Algorithmic problem solving
Exercises
2. Write an algorithm for calculating area and of circumference of circle
algorithm Pseudocode flowchart
29
Algorithmic problem solving
Exercises
3. Write an algorithm to add two numbers entered by user.
31
Algorithmic problem solving
Exercises
4. Convert temperature Fahrenheit to Celsius
32
Algorithmic problem solving
Algorithmic problem solving
33
Algorithmic problem solving
Algorithmic problem solving
34
Algorithmic problem solving
Algorithmic problem solving
35
Algorithmic problem solving
Algorithmic problem solving
37
Algorithmic problem solving
Algorithmic problem solving
Methods of Specifying an Algorithm
Analyzing an Algorithm
1. Efficiency.
• Time efficiency: indicating how fast the algorithm runs,
• Space efficiency: indicating how much extra memory it
uses
2. simplicity.
• An algorithm should be precisely defined and
investigated with mathematical expressions.
• Simpler algorithms are easier to understand and easier
to program.
• Simple algorithms usually contain fewer bugs.
39
Algorithmic problem solving
Algorithmic problem solving
Coding an Algorithm
40
THANK YOU!
MSc. Vo Hoang Thuy Tien
Lecturer and Researcher
+84 937 64 99 14