0% found this document useful (0 votes)
8 views21 pages

Problem Solving and Algorithms LECTURE 4

The document outlines the process of problem-solving in computing, detailing steps such as problem identification, analysis, design, implementation, testing, and maintenance. It introduces algorithms as well-defined instructions for solving problems, along with flowcharts and pseudocode as tools for representation. Additionally, it discusses various problem-solving techniques and applications of algorithms in engineering fields.

Uploaded by

bankyemax001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views21 pages

Problem Solving and Algorithms LECTURE 4

The document outlines the process of problem-solving in computing, detailing steps such as problem identification, analysis, design, implementation, testing, and maintenance. It introduces algorithms as well-defined instructions for solving problems, along with flowcharts and pseudocode as tools for representation. Additionally, it discusses various problem-solving techniques and applications of algorithms in engineering fields.

Uploaded by

bankyemax001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Problem-Solving and

Algorithm Development
LECTURE 4
Introduction to Problem-Solving in Computing
• What is Problem-Solving?
• In computing, problem-solving refers to the process of designing a solution to
a given problem using a systematic approach.
• It involves analyzing the problem, planning a solution, implementing the
solution, and verifying its correctness.
• Steps in Problem-Solving:
• Problem Identification: Clearly define the problem.
• Analysis: Understand the inputs, processes, and outputs involved.
• Design: Create a plan or solution, often using tools like algorithms, flowcharts,
or pseudocode.
• Implementation: Code the solution in a programming language.
• Testing and Evaluation: Verify that the solution works correctly and
efficiently.
• Maintenance: Update and improve the solution over time as needed.
Algorithm Development
• What is an Algorithm?
• An algorithm is a finite set of well-defined instructions that, when followed,
solve a specific problem.

• Characteristics of a good algorithm include:


• Correctness: The algorithm produces the correct output for every valid input.
• Efficiency: The algorithm runs in a reasonable amount of time and uses resources like
memory effectively.
• Clarity: The algorithm is easy to understand and can be implemented by others.
• Example of an Algorithm:
• Finding the largest number in a list:
• Set the first number as the largest.
• Compare each number in the list to the current largest number.
• If a number is larger, update the largest number.
• Return the largest number after all comparisons are made.
• An example of an algorithm people use would be a recipe to make a cake.
• "4 extra large eggs,
• beaten 1&1/2 C. stock
• 1/2 teaspoon salt
• 1 scallion, minced
• 1 C. small shrimp or lobster flakes
• 1 t. soy sauce
• 1 Tablespoon oil
• 1. Mix all the ingredients, except the oil, in a deep bowl.
FLOWCHART
• What is a Flowchart?
• A flowchart is a visual representation of an algorithm or process. It uses
symbols to represent different actions, decisions, or steps in a procedure.
• Flowcharts help in understanding the flow of control and decision-making in
algorithms.
Flowcharting Symbols
General Rules for flowcharting
1. All boxes of the flowchart are connected with Arrows. (Not lines)
2. Flowchart symbols have an entry point on the top of the symbol with no other entry
points. The exit point for all flowchart symbols is on the bottom except for the Decision
symbol.
3. The Decision symbol has two exit points; these can be on the sides or the bottom and one
side.
4. Generally a flowchart will flow from top to bottom. However, an upward flow can be shown
as long as it does not exceed 3 symbols.
5. Connectors are used to connect breaks in the flowchart.
Examples are:
• From one page to another page.
• From the bottom of the page to the top of the same page.
• An upward flow of more then 3 symbols
6. Subroutines and Interrupt programs have their own independent flowcharts.
7. All flow charts start with a Terminal or Predefined Process (for interrupt programs or
subroutines) symbol.
8. All flowcharts end with a terminal or a contentious loop.
• Examples of Algorithms and Flowcharts
1. Design an algorithm and the corresponding flowchart for adding the test
scores as given below: 26, 49, 98, 87, 62, 75.
Solution
• Example 2: The problem with this algorithm is that, some of the steps
appear more than once, i.e. step 5 get second number, step 7, get third
number, etc. One could shorten the algorithm or flowchart as follows:
1. Start START

2. Sum = 0 SUM

3. Get a value
GET VALUE

4. Sum = Sum +value


5. Go to step 3 to get next Value SUM = SUM +
VALUE

6. Output the sum


GO TO STEP 3 TO
GET NEXT VALUE
7. stop
OUTPUT SUM

STOP
pseudocode
what is pseudocode?
 A pseudo-code is the English-like representation of the program logic.
 It is a sequential step-by-step arrangement of the instructions
to be performed to accomplish a task.
 It is an informal and artificial language that helps programmers develop
algorithms.
Example:
1. Write a pseudo code for findings the area of a room.
Solution:
• Begin process
• Input room length
• Input room width
• Multiply length by width to get area
• Print area
• End process
2. Write a Pseudo code for finding the greatest of 3 numbers
represented as A, B, and C.
Solution
• Begin process
• Input A,B,C
• If A>B then big = A
• Else big = B
• If big > C then big = biggest
• Else biggest = C
3. Write an Algorithm to determine a student’s final grade and indicate
whether it is passing or failing. The final grade is calculated as the average
of four marks.
• Solution
• Input a set of 4 marks
• Calculate their average by summing and dividing by 4.
• If average is below 50
Solution for example 3 (below under pseudo code)
• Print “Fail” • Step 1: Input M1, M2, M3, M4
• else • Step 2: Grade ← (M1 + M2 + M3 + M4)/4
• Step 3: If (Grade < 50) then
• Print “Pass” • Print “FALL”
• Print “Pass”
• End it.
Transition from Problem to Algorithm

• Steps for Developing an Algorithm:


1. Understand the Problem: Identify the key requirements, inputs, and
outputs.
2. Plan the Logic: Break the problem into smaller steps and determine how
each step can be handled.
3. Write Pseudocode: Outline the logic in clear, easy-to-understand
language.
4. Create Flowchart (optional): Visualize the flow of the solution to verify the
logic.
5. Code the Solution: Convert the pseudocode or flowchart into a specific
programming language.
• Example:
Write an algorithm to find the maximum of three numbers.
• Solution:
• Step 1: Understand that the algorithm needs to compare three numbers.
• Step 2: Break it down into comparing two numbers at a time.
• Pseudocode:
Start
Input A, B, C
If A > B and A > C
Print A is the largest
Else If B > A and B > C
Print B is the largest
Else
Print C is the largest
End
• Flowchart

• Code the Solution


• ALGORITHM:
• Step 1: Start
• Step 2: Read the three numbers A, B, C
• Step 3: Compare A and B. If A is greater perform step 4 else perform
step 5.
• Step 4: Compare A and C. If A is greater, output “A is greatest” else
output “C is greatest”. Perform step 6.
• Step 5: Compare B and C. If B is greater, output “B is greatest” else
output “C is greatest”.
• Step 6: Stop
Difference between Algorithm, Flowchart, and Pseudo
Code
An algorithm is a sequence of instructions used to solve a particular
problem.
Flowchart and Pseudo code are tools to document and represent the
algorithm.
In other words, an algorithm can be represented using a flowchart or a
pseudo code.
Flowchart is a graphical representation of the algorithm.
Pseudo code is a readable, formally styled English like language
representation of the algorithm.
Both flowchart and pseudo code use structured constructs of the
programming language for representation.
The user does not require the knowledge of a programming language to
write or understand a flowchart or a pseudo code.
Problem-Solving Techniques
• Divide and Conquer: Break down a large problem into smaller, more
manageable sub-problems. Solve each sub-problem and combine the
results to solve the original problem.
• Greedy Approach: Make the locally optimal choice at each stage with
the hope of finding a global optimum.
• Dynamic Programming: Break the problem into overlapping sub-
problems and store solutions to sub-problems to avoid redundant
computations.
• Backtracking: Build a solution incrementally, and backtrack to correct
decisions when encountering a dead end.
Application of Algorithms in Engineering
• Algorithms are used in various engineering fields:
1. Control Systems: Algorithms control machinery and systems for optimal
performance.
2. Signal Processing: Algorithms process signals (like audio and video) for
enhancement, compression, and transmission.
3. Optimization Problems: Engineers use algorithms to find the best solutions
within constraints (e.g., minimizing energy consumption or maximizing output).

You might also like