0% found this document useful (0 votes)
2 views

24dkd-ex-python-week1

The document outlines a Python programming course syllabus, detailing weekly topics and grading criteria. It emphasizes problem-solving techniques, including algorithms, flowcharts, and pseudocode, while discussing their qualities and advantages. Additionally, it covers the importance of algorithm design, efficiency, and the systematic approach to problem-solving in computer science.

Uploaded by

ngavu11022005
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

24dkd-ex-python-week1

The document outlines a Python programming course syllabus, detailing weekly topics and grading criteria. It emphasizes problem-solving techniques, including algorithms, flowcharts, and pseudocode, while discussing their qualities and advantages. Additionally, it covers the importance of algorithm design, efficiency, and the systematic approach to problem-solving in computer science.

Uploaded by

ngavu11022005
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

University of Science, VNU – HCM

Faculty of Physics and Engineering


Department of Physics and Computer Science

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

Problem solving can be expressed in the form of:


1. Algorithms.
2. Flowcharts.
3. Pseudo codes.
4. Programs

5
Algorithmic problem solving
Problem solving techniques
1. Algorithm

It is defined as a sequence of instructions that describe a method for solving a problem.


In other words it is a step by step procedure for solving a problem
• Should be written in simple English
• Each and every instruction should be precise and unambiguous.
• Instructions in an algorithm should not be repeated infinitely.
• Algorithm should conclude after a finite number of steps.
• Should have an end point
• Derived results should be obtained only after the algorithm terminates.

6
Algorithmic problem solving
Problem solving techniques
1. Algorithm

Qualities of a good 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

Building Blocks of 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

Building Blocks of Algorithm: Statements

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

Building Blocks of Algorithm: States

An algorithm is deterministic automation for accomplishing a goal which, given an initial


state, will terminate in a defined end-state.
An algorithm will definitely have start state and end state.

10
Algorithmic problem solving
Problem solving techniques
1. Algorithm

Building Blocks of Algorithm: Control Flow

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

Building Blocks of Algorithm: Control Flow - Sequential control flow

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

Algorithm can be expressed in many different notations, including Natural Language,


Pseudo code, flowcharts and programming languages. Natural language tends to be
verbose and ambiguous. Pseudocode and flowcharts are represented through
structured human language.

A notation is a system of characters, expressions, graphics or symbols designs used


among each others in problem solving to represent technical facts, created to facilitate
the best result for a program

13
Algorithmic problem solving
Problem solving techniques
2. Notations of an algorithm: Pseudo code

Pseudocode is an informal high-level description of the operating principle of a computer


program or algorithm. It uses the basic structure of a normal programming language, but is
intended for human reading rather than machine reading.
It is text based detail design tool. Pseudo means false and code refers to instructions
written in programming language.
Pseudocode cannot be compiled nor executed, and there are no real formatting or syntax
rules. The pseudocode is written in normal English language which cannot be understood by the
computer.

14
Algorithmic problem solving
Problem solving techniques
2. Notations of an algorithm: Pseudo code

Basic rules to write pseudocode

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

Common keywords used in pseudocode

1. //: This keyword used to represent a comment.


2. BEGIN,END: Begin is the first statement and end is the last statement.
3. INPUT, GET, READ: The keyword is used to inputting data.
4. COMPUTE, CALCULATE: used for calculation of the result of the given expression.
5. ADD, SUBTRACT, INITIALIZE used for addition, subtraction and initialization.
6. OUTPUT, PRINT, DISPLAY: It is used to display the output of the program.
7. IF, ELSE, ENDIF: used to make decision.
8. WHILE, ENDWHILE: used for iterative statements.
9. FOR, ENDFOR: Another iterative incremented/decremented tested automatically. 16
Algorithmic problem solving
Problem solving techniques
2. Notations of an algorithm: Pseudo code

Basic rules to write pseudocode

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

Advantages of Pseudocode Disadvantages of Pseudocode


• Can be done easily on a word processor • It is not visual
• Easily modified • There is no standardized style or format
• Implements structured concepts well
• It can be written easily
• It can be read and understood easily
• Converting pseudocode to programming
language is easy as compared with flowchart

18
Algorithmic problem solving
Problem solving techniques
2. Notations of an algorithm: Flowchart

A graphical representation of an algorithm. Flowcharts is a diagram made up of boxes,


diamonds, and other shapes, connected by arrows.
Each shape represents a step in process and arrows show the order in which they occur.

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

3 Process symbol Rectangle Denotes the process to be carried

4 Decision symbol Diamond Represents decision making and branching

Represents the sequence of steps and


5 Flow lines Arrow lines
direction of flow. Used to connect symbols.

A connector symbol is represented by a circle


and a letter or digit is placed in the circle to
6 Connector Circle
specify the link. This symbol is used to connect
flowcharts.

7 Sub function Used to call function


20
Algorithmic problem solving
Problem solving techniques
2. Notations of an algorithm: Flowchart

Rules for drawing flowchart

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

Rules for drawing 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

algorithm Pseudocode flowchart


step 1: start
step 2: get I, b values
step 3: calculate A = I*b
step 4: display A
step 5: stop

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.

algorithm Pseudocode flowchart

31
Algorithmic problem solving
Exercises
4. Convert temperature Fahrenheit to Celsius

algorithm Pseudocode flowchart

32
Algorithmic problem solving
Algorithmic problem solving

Algorithmic problem solving is solving


problem that require the formulation
of an algorithm for the solution.

33
Algorithmic problem solving
Algorithmic problem solving

Understanding the Problem

• It is the process of finding the input of the problem


that the algorithm solves.
• It is very important to specify exactly the set of inputs
the algorithm needs to handle.
• A correct algorithm is not one that works most of the
time, but one that works. Correctly for all legitimate
inputs.

34
Algorithmic problem solving
Algorithmic problem solving

Ascertaining the Capabilities of the


Computational Device

• If the instructions are executed one after another, it is


called sequential algorithm

35
Algorithmic problem solving
Algorithmic problem solving

Choosing between Exact and Approximate


Problem Solving

• The next principal decision is to choose between


solving the problem exactly or solving it
approximately.
• Based on this, the algorithms are classified as exact
algorithm and approximation algorithm.
• Data structure plays a vital role in designing and
analysis the algorithms.
• Some of the algorithm design techniques also
depend on the structuring data specifying a
problem’s instance
Algorithm+ Data structure=programs. 36
Algorithmic problem solving
Algorithmic problem solving

Algorithm Design Techniques

• An algorithm design technique (or “strategy” or


“paradigm”) is a general approach to solving
problems algorithmically that is applicable to a
variety of problems from different areas of computing.
• Learning these techniques is of utmost importance for
the following reasons.
• First, they provide guidance for designing algorithms
for new problems. Second, algorithms are the
cornerstone of computer science.

37
Algorithmic problem solving
Algorithmic problem solving
Methods of Specifying an Algorithm

• In the earlier days of computing, the dominant vehicle for


specifying algorithms was a flowchart, a method of expressing
an algorithm by a collection of connected geometric shapes
containing descriptions of the algorithm’s steps.
• Programming language can be fed into an electronic
computer directly. Instead, it needs to be converted into a
computer program written in a particular computer language.
We can look at such a program as yet another way of
specifying the algorithm, although it is preferable to consider it
as the algorithm’s implementation.
• Once an algorithm has been specified, you have to prove its
correctness. That is, you have to prove that the algorithm yields
a required result for every legitimate input in a finite amount of
time. 38
Algorithmic problem solving
Algorithmic problem solving

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

• Most algorithms are destined to be ultimately


implemented as computer programs. Programming an
algorithm presents both a peril and an opportunity.
• A working program provides an additional opportunity in
allowing an empirical analysis of the underlying
algorithm. Such an analysis is based on timing the
program on several inputs and then analyzing the results
obtained

40
THANK YOU!
MSc. Vo Hoang Thuy Tien
Lecturer and Researcher

+84 937 64 99 14

[email protected]

University of Science, VNU – HCM


227 Nguyen Van Cu, Ward 4, District 5, Ho Chi Minh City

You might also like