Professional Documents
Culture Documents
I D : H U N G N P B H A F 2 0 01 24
C L A S S : P B I T 1710 2
Programing
1. Introduction
2. Algorithm
a. Definition
b. For example
c. Ways to demonstrate Algorithms
d. Characteristics of algorithms
e. Types of algorithm
5. Summary
1. Introduction
• A programming language
is a form of language
created according to
specific rules to help
humans communicate
and command
computers to do things.
• Programming is the
foundation of all
computer software today.
2. Algorithm
Definition
For example
Ways to demonstrate algorithms
Characteristics of algorithms
Types of algorithm
a. Definition
An ellipse is used to represent the
o An algorithm is a set of start and end of an algorithm
instructions to solve different
problems in order of steps
with a beginning and an end. Parallelogram to represent inputs
and outputs.
o In mathematics and
computer science, an Rectangles are used to represent the
algorithm usually means a process taken to solve the problem.
small procedure that solves a
recurrent problem.
The rhombus is used to represent
the conditions of the algorithm.
> Problem: Find min, max of two numbers a, b
> Input: a, b
- Recursive Algorithm
- Divide and Conquer Algorithm
- Dynamic Programming Algorithm
- Greedy Algorithm
- Brute Force Algorithm
- Backtracking Algorithm
Recursive Algorithm
A recursive algorithm is an algorithm which calls itself with "smaller (or simpler)" input
values, and which obtains the result for the current input by applying simple operations to the
returned value for the smaller (or simpler) input.
▪ Divide the problem into a number of subproblems that are smaller instances of
the same problem.
▪ Conquer the subproblems by solving them recursively. If they are small
enough, solve the subproblems as base cases.
▪ Combine the solutions to the subproblems into the solution for the original
problem.
▪ Example: Divide bread into equal portions
Dynamic Programming Algorithm
An algorithm that always takes the best immediate, or local, solution while finding an answer. Greedy
algorithms find the overall, or globally, the optimal solution for some optimization problems, but may find
less-than-optimal solutions for some instances of other problems.
Brute Force Algorithm
In computer science, brute-force search or exhaustive search, also known as generating and test, is a very
general problem-solving technique and algorithmic paradigm that consists of systematically enumerating
all possible candidates for the solution and checking whether each candidate satisfies the problem's
statement.
Example: Crossword puzzles
Backtracking Algorithm
Backtracking is a general algorithm for finding all (or some) solutions to some computational problems,
notably constraint satisfaction problems, that incrementally builds candidates to the solutions, and
abandons a candidate ("backtracks") as soon as it determines that the candidate cannot possibly be
completed to a valid solution.
Example: Eight queens puzzle
3. Steps in program
development
a. Defining the problem
Analyze the problem. The computer user must figure out the problem,
then decide how to resolve the problem - choose a program
In this step, the programmer will most likely determine the inputs,
processing activities, and the expected output of the program.
Coding means using the programming language to get the computer to behave as desired. Each
line of the code is a set of instructions for the computer. A set of codes form a script, and a set or
dozens of sets, form a program
o This is possible by coding the program with the use of a specific programming language like:
Java, Pascal, C++, Visual basic etc.
o While coding, the computer will compile the source code into machine code for the program to
run.
▪ Source code vs Machine code
Source code
d. Testing and Debugging
•Testing is the process or method of finding errors in a software application or program so that the
application functions according to the end-users..
•Debugging is the action where the development team or a developer implements after receiving the test
report related to the bugs in the software from the testing team.
Error detection
Debugging
Error message
Testing vs Debugging
Testing Debugging
• Can be performed either manually or • Cannot be automated.
with the help of some automation tools.
• After the implementation of the
• Once the coding phase is done, we test case, we can start the Debugging
proceed with the testing process. process.
• Is the presentation of defects. • Is a logical procedure.
e. Documenting the program
❑ This is writing of formal support materials explaining how the program was developed
❑ All stages of the program development should be documented in order to help during
future modification of the program.
❑ There are 2 types of document that the programmer should provide after finishing testing
which are:
• Internal documentation: is written as program comments that cannot be executed by
the program editor. They help programmers to understand the source code
• External documentation: refers to reference materials such as user manuals printed as
booklets. User manuals are common examples of external documentation.
f. Deploying and maintaining the program
• Provide education and support to end users; correct any unanticipated errors that emerge and identify
user-requested modifications.
5. Applications of
algorithms and
problem solving
_________________Problem_________________
➢ Action:
- Design program
- Draw a flowchart showing how to manage books and readers
FLOWCHART
FOR THE
PROBLEM
Coding the program
Machine code
source code
5. SUMMARY
Here are the key takeaways:
▪ Algorithm