Computer Science
Compiled by: Sir Danish Shakeel
For Grade 10th
(Board of Secondary Education Karachi)
Ch. 01 – Problem Solving &
Algorithm Designing
Ch. 01 – Problem Solving & Algorithm Designing
Acknowledgement
• The contents of this
lecture have been taken
Compiled by: Sir Danish Shakeel
from this Book:
Ch. 01 – Problem Solving & Algorithm Designing
Ch. 01 – Problem Solving & Algorithm Designing
Compiled by: Sir Danish Shakeel
Ch. 01 – Problem Solving & Algorithm Designing
Problem
• Q. Define the term Problem?
Compiled by: Sir Danish Shakeel
Ch. 01 – Problem Solving & Algorithm Designing
Problem
• Q. Define the term Problem?
Compiled by: Sir Danish Shakeel
• A problem is a situation preventing something
from being achieved.
• A problem can be a task, a situation or any other
thing.
• Problem is considered to be a matter which is
difficult to solve or settle.
Ch. 01 – Problem Solving & Algorithm Designing
Problem Solving
Q. What is Problem Solving?
Compiled by: Sir Danish Shakeel
Ch. 01 – Problem Solving & Algorithm Designing
Problem Solving
• Q. What is a Problem Solving?
Compiled by: Sir Danish Shakeel
• Problem solving is the process of finding
Solutions of difficult or complex issues.
• It is the process by which any kind of problem is
solved.
• Solving problems is the core feature of
computers.
Ch. 01 – Problem Solving & Algorithm Designing
Problem Solving Strategies
• Q. What are problem solving strategies?
Compiled by: Sir Danish Shakeel
Ch. 01 – Problem Solving & Algorithm Designing
Problem Solving Strategies
• Q. What are problem solving strategies?
Compiled by: Sir Danish Shakeel
• A very important aspect of problem solving is
developing good strategies.
• There are many strategies for solving a problem.
• A strategy is an approach created to solve a
computational problem strategies are designed
according to the nature of the problem.
Ch. 01 – Problem Solving & Algorithm Designing
Problem Solving Process
• Q. Explain the process of problem solving.
Compiled by: Sir Danish Shakeel
Ch. 01 – Problem Solving & Algorithm Designing
Problem Solving Process
• Q. Explain the process of problem solving.
Compiled by: Sir Danish Shakeel
• Problem solving is a step by step process. There
are four basic steps involved in finding a solution
for a problem as given below:
1. Define the problem.
2. Generate alternative solutions.
3. Evaluate and select an alternative.
4. Implement and follow up on the solution.
Ch. 01 – Problem Solving & Algorithm Designing
Problem Solving Process
• Define the problem:
• The first step is defining or identifying the
Compiled by: Sir Danish Shakeel
problem.
• It involves diagnosing the situation so that the
focus should be on the real problem and not on
its symptoms.
• During the first stage of problem solving, it is
important to describe the problem.
Ch. 01 – Problem Solving & Algorithm Designing
Problem Solving Process
• Generate Alternative Solutions:
• For any problem, there are more solutions to it
Compiled by: Sir Danish Shakeel
than the one that is thought of first.
• Postpone the selection of one solution until
several problem solving alternatives have been
proposed.
• Considering multiple alternatives can significantly
enhance the value of your ideal solution.
Ch. 01 – Problem Solving & Algorithm Designing
Problem Solving Process
• Evaluate and Select an Alternative:
• Many alternative solutions to the problem should
Compiled by: Sir Danish Shakeel
be generated before final evaluation.
• A common mistake in problem solving is that
alternatives are evaluated as they are proposed,
so the first acceptable solution is chosen, even if
it is not the best solution.
Ch. 01 – Problem Solving & Algorithm Designing
Problem Solving Process
• Implement and Follow Up on the Solution:
• When the best solution is implemented, it is
Compiled by: Sir Danish Shakeel
important to track and measure the results to be
able to answer questions such as:
• Did it work? Was this a good solution? Did we
learn something here?
Ch. 01 – Problem Solving & Algorithm Designing
Questions for Home Work
• The answers of this question need to written in
Computer Science Notebook:
Compiled by: Sir Danish Shakeel
• Q. Using problem solving process, find a
solution to a problem (you can think about any
problem).
• Hint: Discuss each step of the problem solving
process in your answer.
Ch. 01 – Problem Solving & Algorithm Designing
Algorithm
• Q. Define the term Algorithm.
• An algorithm is a set of instructions, steps, rules
Compiled by: Sir Danish Shakeel
that are followed to solve a problem.
• It is a tool for solving a well specified computational
problem.
• There are two common methods to express
algorithm designs:
1. Pseudocode
2. Flowcharts.
Ch. 01 – Problem Solving & Algorithm Designing
Role of Algorithm
• Q. Discuss the role of Algorithm in problem solving.
• The advantage of using an algorithm to solve a
Compiled by: Sir Danish Shakeel
problem or make a decision is that it produces the
best possible answer every time.
• This is useful in solutions where accuracy is required
or very similar problems need to be solved more
often.
• In many cases, computer programs can be
developed with the help of this process.
Ch. 01 – Problem Solving & Algorithm Designing
Qualities of a Good Algorithm
• Q. What are the qualities of a good algorithm?
• Input and output should be defined precisely.
Compiled by: Sir Danish Shakeel
• Each step in the algorithm should be clear.
• Algorithms are supposed to be most effective among
many different ways to solve a problem.
• An algorithm should not include computer code. The
algorithm should be written in a way that it can be
used in different programming languages.
Ch. 01 – Problem Solving & Algorithm Designing
Algorithm Examples
• Algorithm – 1: Making a cup of Tea.
• Step 1: Start
Compiled by: Sir Danish Shakeel
• Step 2: Play the fresh water in a pot or a kettle.
• Step 3: Boil the water.
• Step 4: Put the black tea leaves in the pot.
• Step 5: After that add some milk into that pot.
• Step 6: Add some sugar.
• Step 7: Boil for some time.
• Step 8: Stop
Ch. 01 – Problem Solving & Algorithm Designing
Algorithm Examples
• Algorithm – 2: Sum of Two Numbers.
• Step 1: Start
Compiled by: Sir Danish Shakeel
• Step 2: Declare variables num1, num2 and sum.
• Step 3: read values num1 and num2.
• Step 4: Add num1 and num2 and assign the
result to sum. sum = num1 + num2
• Step 5: Display sum.
• Step 6: Stop
Ch. 01 – Problem Solving & Algorithm Designing
Algorithm Examples
• Algorithm – 3:
• Q. Design an algorithm to find the average of
Compiled by: Sir Danish Shakeel
three numbers.
Ch. 01 – Problem Solving & Algorithm Designing
Algorithm Examples
• Algorithm – 3: Average of three numbers.
• Step 1: Start
Compiled by: Sir Danish Shakeel
• Step 2: Declare variables num1, num2, num3 and
average.
• Step 3: Read values num1, num2 and num3.
• Step 4: Apply formula
avg=(num1+num2+num4)/3
• Step 5: Display avg.
• Step 6: Stop
Ch. 01 – Problem Solving & Algorithm Designing
Algorithm Examples
• Homework:
• Algorithm – 4:
Compiled by: Sir Danish Shakeel
• Q. Design an algorithm to find the volume of a
box.
Ch. 01 – Problem Solving & Algorithm Designing
Flowchart
• Q. What is a Flowchart?
Compiled by: Sir Danish Shakeel
Ch. 01 – Problem Solving & Algorithm Designing
Flowchart
• Q. What is a Flowchart?
• Flow chart is a general-purpose tool use to define
the sequence of different types of processes or
Compiled by: Sir Danish Shakeel
operations in information system or program.
• It describes graphically different steps of a program
or any operation and their sequence or flow using
different symbols.
• it is a diagrammatic or graphical representation of
algorithm and converts word off algorithm into
symbols.
Ch. 01 – Problem Solving & Algorithm Designing
Flowchart Symbols
• Q. Name and describe different flowchart
symbols.
Compiled by: Sir Danish Shakeel
Ch. 01 – Problem Solving & Algorithm Designing
Flowchart Symbols
• Name: Start/Stop
Compiled by: Sir Danish Shakeel
• Symbol:
• Description:
• It is oval shape and is used to show the start and
end of a program or flowchart sequence.
Ch. 01 – Problem Solving & Algorithm Designing
Flowchart Symbols
• Name: Arrows
Compiled by: Sir Danish Shakeel
• Symbol:
• Description:
• The arrow shape shows direction of flow from
one step or box to another.
Ch. 01 – Problem Solving & Algorithm Designing
Flowchart Symbols
• Name: Process
Compiled by: Sir Danish Shakeel
• Symbol:
• Description:
• The rectangle shape indicates any type of
internal operation or process usually one step.
• The step is written inside the box.
• Only one arrow goes out of the box.
Ch. 01 – Problem Solving & Algorithm Designing
Flowchart Symbols
• Name: Input/Output
Compiled by: Sir Danish Shakeel
• Symbol:
• Description:
• This parallelogram shape shows the input or
output process.
• It is used for any input or output operation and
indicates that the computer is to obtain data or
output results.
Ch. 01 – Problem Solving & Algorithm Designing
Flowchart Symbols
• Name: Decision / Condition
Compiled by: Sir Danish Shakeel
• Symbol:
• Description:
• This diamond shape shows decision based on a
condition written in the diamond.
• Two arrows go out of the diamond.
• One directs toward path if condition is true
another for false.
Ch. 01 – Problem Solving & Algorithm Designing
Importance of Flowchart
• Q. What is the importance of a flowchart?
• Flowcharts help in communicating the logic of a
Compiled by: Sir Danish Shakeel
problem to all others and make it easy to
understand.
• It is a useful program document that is needed for
various purposes like to know about the program
quickly or to modify program logic.
• The flow chart acts as a guide or blueprint during the
coding of a program.
Ch. 01 – Problem Solving & Algorithm Designing
A Sample Flowchart
• The following flowchart takes three numbers as
input, calculates sum and percentage. If
Compiled by: Sir Danish Shakeel
percentage is above 70 then prints “Well done”,
otherwise “Work hard”.
Ch. 01 – Problem Solving & Algorithm Designing
A Sample Flowchart
• The following flowchart
takes three numbers as
Compiled by: Sir Danish Shakeel
input, calculates sum and
percentage. If percentage
is above 70 then prints
“Well done”, otherwise
“Work hard”.
Ch. 01 – Problem Solving & Algorithm Designing
Difference between Algorithm & Flowchart
• Q. Differentiate between algorithm and flowchart?
Compiled by: Sir Danish Shakeel
Ch. 01 – Problem Solving & Algorithm Designing
Data Structure
• What is data structure?
• A data structure is a particular way of organizing
Compiled by: Sir Danish Shakeel
data in a computer to use it effectively.
• For example, array data structure is used to store
a list of items having the same data type.
• Data structure may be linear or non-linear.
Ch. 01 – Problem Solving & Algorithm Designing
Linear Data Structures
• What is linear data structure? Give examples.
• In linear data structure data elements are arranged in
sequential order and each of the elements is connected to its
Compiled by: Sir Danish Shakeel
previous and next element.
• This structure helps to convert a linear data structure in a
single level and in single run.
• They are easy to implement as computer memory is also in a
sequential form.
• Linear data structures are not efficient in memory utilization.
• Examples of linear data structures are Stack, Queue, Array etc.
Ch. 01 – Problem Solving & Algorithm Designing
Linear Data Structures
• 1. Stack:
Compiled by: Sir Danish Shakeel
Ch. 01 – Problem Solving & Algorithm Designing
Linear Data Structures
• 1. Stack:
• Stack is a linear data structure which follows a
particular order to perform different operations.
Compiled by: Sir Danish Shakeel
• Items may be added or removed only at the top of
stack.
• The order may be LIFO (Last In First Out) or FILO
(First In Last Out).
• The data which is placed first is removed in last and
which is placed last is removed first.
Ch. 01 – Problem Solving & Algorithm Designing
Linear Data Structures
• 1. Stack:
• The term “push” is used to insert a new element
Compiled by: Sir Danish Shakeel
into the stack and “pop” is used to remove an
element from the stack.
• Insertion and removal can be done at one end
called loop.
• Stack is in overflow state when it is completely
full and is in underflow state is it is completely
empty.
Ch. 01 – Problem Solving & Algorithm Designing
Linear Data Structures
• 2. Queue:
Compiled by: Sir Danish Shakeel
Ch. 01 – Problem Solving & Algorithm Designing
Linear Data Structures
• 2. Queue:
• A Queue is a linear data structure which follows a
Compiled by: Sir Danish Shakeel
particular order in which operations are
performed in FIFO (First In First Out) method,
which means that element inserted first will be
removed first.
Ch. 01 – Problem Solving & Algorithm Designing
Linear Data Structures
• 3. Array:
Compiled by: Sir Danish Shakeel
Ch. 01 – Problem Solving & Algorithm Designing
Linear Data Structures
• 3. Array:
• Array is a linear data structure, which holds a list of
finite data elements of same data type.
Compiled by: Sir Danish Shakeel
• Each element of array is referenced by a set of index
of consecutive numbers.
• The elements of areas stored in successive memory
locations.
• Most of the data structures make use of arrays to
implement their algorithms.
Ch. 01 – Problem Solving & Algorithm Designing
Linear Data Structures
• 3. Array:
• Two terms are necessary to understand array:
Compiled by: Sir Danish Shakeel
• Element: Each item stored in an array is called an
element.
• Index: Each location of an element in an array
has a numerical value called index which is used
to identify the element.
Ch. 01 – Problem Solving & Algorithm Designing
Non-Linear Data Structures
• The elements of a nonlinear data structure are
not connected in a sequence.
Compiled by: Sir Danish Shakeel
• Each element can have multiple paths to connect
to other elements.
• They support multi level storage and often
cannot be traversed in single run.
Ch. 01 – Problem Solving & Algorithm Designing
Non-Linear Data Structures
• Such data structures are difficult to implement
but are more efficient in utilizing computer
Compiled by: Sir Danish Shakeel
memory.
• Examples of nonlinear data structures are tree,
graphs etc.
Ch. 01 – Problem Solving & Algorithm Designing
Non-Linear Data Structures
• 1. Tree:
Compiled by: Sir Danish Shakeel
Ch. 01 – Problem Solving & Algorithm Designing
Non-Linear Data Structures
• 1. Tree:
• This nonlinear data structure is used to represent data
containing hierarchical relationship between elements.
Compiled by: Sir Danish Shakeel
• Tree represents its elements as the nodes connected to
each other by edges.
• In each tree collection, we have one root node, which is
the very first node in our tree.
• If a node is connected to other node element, it is called a
parent node and the connected node is called its child
node.
Ch. 01 – Problem Solving & Algorithm Designing
Non-Linear Data Structures
• 1. Tree:
• There is also a binary tree or binary search tree.
Compiled by: Sir Danish Shakeel
• A binary tree is a special data structure use to
store data in which each node can have a
maximum of two children will stop each node
element may or may not have child nodes.
Ch. 01 – Problem Solving & Algorithm Designing
Non-Linear Data Structures
• 2. Graph:
Compiled by: Sir Danish Shakeel
Ch. 01 – Problem Solving & Algorithm Designing
Non-Linear Data Structures
• 2. Graph:
• A graph is a non-linear data structure consisting of
data elements called nodes / vertices and edges that
Compiled by: Sir Danish Shakeel
are lines that connect any two nodes in that graph.
• Each element or node can contain information like
roll number, name of a student, marks etc.
• In graph each node can have any number of edges,
there is no any node called root or child.
• A cycle can also be formed.
Ch. 01 – Problem Solving & Algorithm Designing
Non-Linear Data Structures
• 2. Graph:
• In the given figure, circles represent nodes or
Compiled by: Sir Danish Shakeel
vertices, while lines represent edges. Graphs are
used to solve network problems.
• Examples of networks include telephone
networks, social networks like Facebook etc.
• Types of Graphs:
• There are two types of graphs:
Ch. 01 – Problem Solving & Algorithm Designing
Non-Linear Data Structures
• (a) Undirected Graph:
• In an undirected graph, nodes are connected by
Compiled by: Sir Danish Shakeel
edges that are all bidirectional.
• For example if an edge connects node 1 and 2,
we can traverse from node 1 to node 2 and from
node 2 to 1.
Ch. 01 – Problem Solving & Algorithm Designing
Non-Linear Data Structures
• (b) Directed Graph:
• In a directed graph, nodes are connected by
Compiled by: Sir Danish Shakeel
directed edges.
• They only go in one direction.
• For example, if an edge connects node 1 and 2,
but the arrow head points towards 2, we can
only traverse from node 1 to node 2, not in the
opposite direction.
Ch. 01 – Problem Solving & Algorithm Designing
End-of-Chapter Questions
Compiled by: Sir Danish Shakeel
Ch. 01 – Problem Solving & Algorithm Designing
End-of-Chapter Questions
Compiled by: Sir Danish Shakeel
Ch. 01 – Problem Solving & Algorithm Designing
End-of-Chapter Questions
Compiled by: Sir Danish Shakeel
Ch. 01 – Problem Solving & Algorithm Designing