0% found this document useful (0 votes)
48 views49 pages

9th Class Computer Science Notes 2024 CH 1

Uploaded by

mirzaahmad1137
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)
48 views49 pages

9th Class Computer Science Notes 2024 CH 1

Uploaded by

mirzaahmad1137
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/ 49

Unit– 1 Problem Solving

Topic No. Title Page No.


Problem Solving Steps
 Defining a problem
 Understanding a Problem
1.1 02
 Planning a solution
 Defining a candid solution
 Selecting the best solution
Flowcharts
 Definitions
 Importance of flowchart in problem solving
1.2 10
 Determining the requirements for a flowchart
 Flowchart symbols
 Examples of flowcharts
Algorithms
 Definition
 Role of algorithms in problem solving
 Formulation of an algorithms
1.3 21
 Examples of algorithms
 Efficiency of algorithms
 Difference between an algorithm and a
flowchart
Test Data
1.4  Importance of Testing 30
 Types of test data
1.5 Verification and validation 33
Identification and correction of errors
1.6  Trace Table 34
 Using invalid data for testing
Exercise
 Long Questions
 Choose the Correct Option (MCQs)
* 39
 Fill in the Blanks
 Flowcharts
 Activity

COMPUTER SCIENCE-9 1
Unit– 1 Problem Solving

1.1 PROBLEM SOLVING STEPS


LONG QUESTIONS
Q.1 What is meant by „defining a problem‟? Write down different strategies to define a
problem.
Ans: DEFINING A PROBLEM (K.B+U.B)
Definition:
A well-defined problem is the one that does not contain ambiguities. All the conditions
are clearly specified and it has a clear goal. It is easy to understand and solve.”
Explanation:
Given a problem statement, first we need to see whether the problem is defined well or
not.
If the problem is not defined well than we can use one of the following strategies to
define the problem:
 Gain Background knowledge
 Use Guesses
 Draw a Picture
Gain Background Knowledge:
We try to know the situation and circumstances in which the problem is happening. In
this way, we can identify the given state. It also helps to know what a good solution will
look like. How we shall be able to measure the solution.
Use Guesses:
We try to guess the unknown information through appropriate guesses. These guesses
may be bases upon our past experiences.
Draw a Picture:
If the problem is not well-defined, we can draw a picture and fill the undefined
information.
Q.2 Define problem analysis. Explain your answer along with an example. (Ex. Q-2) (K.B+A.B)
Ans: PROBLEM ANALYSIS
Definition:
Problem analysis is the process to figure out 5 W‟s (what, who, when, where, and why)
from a problem statement. Problem analysis helps to understand a given problem. These
are the basic elements which lead towards the solution of a given problem.
Understanding a Problem:
It is important to understand the problem before jumping into the solution of the problem.
For example, a riddle or a puzzle can be answered only after clear understanding.
A clear understanding of a problem makes it easier to solve and helps to save money,
time and resources.
Example:
Consider the following problem statement:
“Suppose your class teacher assigns you a task to prepare a list of students in your school
whose names start with letter „A‟. The list is required in order to prepare an alphabetical
directory of all school students and there is only one week to complete the task.”
We can analyses this problem by identifying 5Ws in the problem statement as given
below:
 What: List of students' names starting with letter „A‟.

COMPUTER SCIENCE-9 2
Unit– 1 Problem Solving
 Who: Students.
 Why: To prepare the directory of students.
 When: Within a week.
 Where: School.
Metaphorical Representation:
The following figure shows the metaphorical representation of problem where the red
light presents a problem, the yellow light represents its analysis and the green light
presents the solution. It shows that problem analysis makes us closer to a solution.

Fig: From problem to solution


Q.3 Write down different strategies for planning a solution. How can we select best strategy
for a solution? (K.B+U.B)
Ans: PLANNING A SOLUTION
After analyzing a problem, we formulate a plan that may lead us towards the solution of a
problem.
Strategies:
This phase includes finding the right strategy for problem solving. Some of the strategies are:
 Divide and Conquer
 Guess, Check and Improve
 Act it Out
 Prototype (Draw)
Divide and Conquer:
This strategy divides a complex problem into smaller problems.
Guess, Check and Improve:
The designer guesses a solution to a problem and then checks the correctness of the
solution. If the solution is not according to expectations, then he/she refines the solution.
The refinement is an iterative process.
Act it Out:
In this strategy the designer defines the list of "to-do" tasks. Afterwards he/she performs
the task.
Prototype (Draw):
This technique draws a pictorial representation of the solution. It is not the final solution.
However, it may help a designer to understand the important components of the solution.
SELECT A BEST STRATEGY
The selection of a strategy depends upon the problem. It is quite important that one
strategy maybe more suitable to implement a solution than the other one. Very
specifically, the selection of the strategy depends upon the nature of a problem.
Q.4 What is meant by candid solutions? Explain with an example. (K.B+U.B+A.B)
Ans: CANDID SOLUTIONS
COMPUTER SCIENCE-9 3
Unit– 1 Problem Solving
Candid and Candid Solution:
The word candid refers to something spontaneous and unplanned. The solution which
you think is a candid solution. It is not necessary that the candid solution is the actual
solution of a problem.
Example:
If you are asked to find number of students in your school who can play cricket. You
can estimate by finding cricket players in your class and then multiplying it by the total
number of classes in your school. Your answer in this way is the candid solution. To
find exact number of cricket players, you have to opt some other way, like visiting each
class or getting data from teachers. One can think of a candid solution anytime. A
candid solution can help to save time.
The following figure, there are different ways shown to reach a certain place (which
can be reached either by going across the wall or by going sideways) and the one you
think can work, is the candid solution. It is not necessary that the candid solution is the
actual solution of a problem.

Figure: Multiple solutions of a problem


Q.5 How can we select the best solution of a problem? Explain. (K.B+U.B)
Ans: SELECTING THE BEST SOLUTION
Sometimes we find more than one solution of a problem and select the best one amongst them.
Example:
Assume that names of all the students in your school are available on a website and you
are asked to search a particular name. You can solve this search problem by either of the
following methods:
 Look at each name on the website one by one until the name is found or the list is
over.
 Take printouts and search the required name.
 Copy names, put them in Excel sheet and sort there in alphabetical order. Searching
in a sorted list is comparatively easy.
 Just press Ctrl + F, when the list is available in a web browser. You can type the
name to search automatically.
There can be other solutions as well. Now we can identify a solution that has less number
of steps or that seems more effective based on some criteria.
Following figure describe the levels of solution:

COMPUTER SCIENCE-9 4
Unit– 1 Problem Solving

Figure: Levels of a solution


SHORT QUESTIONS
Q.1 Define problem solving. Enlist different steps of problem-solving process. (K.B)
Ans: PROBLEM SOLVING
Definition:
Problem solving is a systematic approach that we can follow to solve a problem systematically.
Problem Solving Steps:
Problem solving steps are as follows:
 Defining a Problem
 Understanding a Problem
 Planning a Solution
 Defining Candid Solutions
 Selecting the Best Solution
Q.2 What is meant by defining a problem? (K.B)
Ans: DEFINING A PROBLEM
Definition:
A well-defined problem is the one that does not contain ambiguities. All the conditions
are clearly specified and it has a clear goal. It is easy to understand and solve.
Q.3 Describe some strategies to define a problem. (K.B)
Ans: STRATEGIES TO DEFINE A PROBLEM
If the problem is not defined well than we can use one of the following strategies to
define the problem.
 Gain Background knowledge
 Use Guesses
 Draw a Picture
Q.4 Why we draw a picture of a problem? (U.B)

COMPUTER SCIENCE-9 5
Unit– 1 Problem Solving
Ans: DRAW A PICTURE
„Draw a picture‟ is a strategy to define the problem. If the problem is not well-defined,
we can draw a picture and fill the undefined information.
Pictorial representation of a problem is a best and easy way to define the problem.

COMPUTER SCIENCE-9 6
Unit– 1 Problem Solving
Q.5 Solve the following problem. (A.B)

Ans: SOLUTION
Method 1:

Method 2:

Let pictures
=x =y =z
According to condition 1 According to condition 2 According to condition 3
x + x + x = 30 x + y + y = 18 y–z=2
3x = 30 x + 2y = 18 put y = 4
x = 10 put x = 10 4–z=2
10 + 2y = 18 –z=2–4
2y = 18 – 10 –z=–2
2y = 8 z=2
y=4
According to condition 4
=a= =b=
a+xb
= 1 + 10  2
= 1 + 20
= 21
COMPUTER SCIENCE-9 7
Unit– 1 Problem Solving
Q.6 What is the importance of understanding a problem? (K.B)
Ans: UNDERSTANDING A PROBLEM
It is very important to understand the problem before jumping into the solution of the
problem because no one can solve the problem without understanding it. A clear
understanding of a problem makes it easier to solve and helps to save money, time and
resources.
Example:
A riddle or a puzzle can be answered only after clear understanding.
Q.7 Define problem analysis. (K.B)
Ans: PROBLEM ANALYSIS
Definition:
Problem analysis is the process to figure out 5 W‟s (what, who, when, where, and why)
from a problem statement. Problem analysis helps to understand a given problem. These
are the basic elements which lead towards the solution of a given problem.
Q.8 What is meant by planning a solution? Name some strategies for planning a solution. (K.B)
Ans: PLANNING A SOLUTION
Definition:
After analyzing a problem, we formulate a plan that may lead us towards the solution of a
problem. This phase includes finding the right strategy for problem solving.
STRATEGIES FOR PLANNING A SOLUTION
Some of the strategies for planning a solution are:
 Divide and Conquer
 Guess, Check and Improve
 Act it Out
 Prototype (Draw)
Q.9 Define divide and conquer. (K.B)
Ans: DIVIDE AND CONQUER
Definition:
It is a strategy for planning a solution. In this strategy, divides a complex problem into
smaller problems.
Q.10 What is meant by prototype? (K.B)
Ans: PROTOTYPE
Definition:
It is a strategy for planning a solution. This technique draws a pictorial representation of
the solution. It is not the final solution. However, it may help a designer to understand the
important components of the solution.
Q.11 How can we select best strategy for planning a solution? (K.B+U.B)
Ans: SELECTION
The selection of a strategy depends upon the problem. It is quite important that one strategy
maybe more suitable to implement a solution than the other one. Very specifically, the
selection of the strategy depends upon the nature of a problem.
Q.12 What is candid and candid solutions? (K.B)
Ans: CANDID AND CANDID SOLUTIONS
The word candid refers to something spontaneous and unplanned. There are multiple
solutions for a problem. The one you think can work, is the candid solution. It is not
necessary that the candid solution is the actual solution of a problem.

COMPUTER SCIENCE-9 8
Unit– 1 Problem Solving

MULTIPLE CHOICE QUESTIONS


1. Problem solving is the process of solving ____________. (U.B)
(A) Simple Problems (B) Language problems
(C) Mathematical Problems (D) Complex Problems
2. Steps of problem solving: (K.B)
(A) 4 (B) 5 (C) 6 (D) 7
3. The first step of problem-solving method is: (K.B)
(A) Defining a problem (B) Understanding a problem
(C) Planning a solution (D) Defining candid solutions
4. The last step of problem-solving method is: (K.B)
(A) Defining a problem (B) Understanding a problem
(C) Selecting the best solution (D) Defining candid solutions
5. Gain Background Knowledge is a strategy of: (U.B)
(A) Defining a problem (B) Understanding a problem
(C) Selecting the best solution (D) Defining candid solutions
6. Use guesses and draw a picture is a strategy of: (U.B)
(A) Defining a problem (B) Understanding a problem
(C) Selecting the best solution (D) Defining candid solutions
7. Albert Einstein said, "If I were given one hour to save the planet, I would spend
________ minutes defining the problem and _________ minute resolving it".: (K.B)
(A) 30, 30 (B) 40, 20 (C) 59, 1 (D) 20, 40
8. 5 Ws are the part of which step? (K.B)
(A) Defining a problem (B) Understanding a problem
(C) Selecting the best solution (D) Defining candid solutions
9. Divide and Conquer rule is a part of: (K.B)
(A) Defining a problem (B) Planning a solution
(C) Selecting the best solution (D) Defining candid solutions
10. This strategy divides a complex problem divides into smaller problems: (K.B+U.B)
(A) Divide and Conquer rule (B) Prototype
(C) Guesses (D) Candid solutions
11. Prototype means: (K.B)
(A) Selecting the best solution (B) Planning a solution
(C) Draw pictorial representation of a solution (D) Defining candid solutions
12. Defines a list of “to-do” task means: (K.B)
(A) Prototype (B) Act it out (C) Divide and Conquer(D) Candid solution
13. The word __________ refers to something spontaneous and unplanned. (K.B+U.B)
(A) Problem (B) Best (C) Select (D) Candid
14. Mark this statement: “Candid solution is the actual solution of a problem.” (K.B+U.B)
(A) Sometimes True (B) Sometimes False (C) Both A and B (D) None of these
15. There can be _________ solution of a problem. (K.B)
(A) Only one (B) Exactly three (C) Many (D) Only four
COMPUTER SCIENCE-9 9
Unit– 1 Problem Solving

ACTIVITY QUESTIONS
Activity 1.1 (A.B)
Students are put in groups of two or three, and each group is provided two different lists of
students‟ names.
One list contains the marks of students in mathematics subject while the other list is for
physics subject. Each group is supposed to prepare the following lists.
a) Top 5% students in mathematics.
b) Top 5% students in physics.
c) Students having more than 90% marks in both subjects.
Identify 5 Ws for this problem.
SOLUTION
We can analyse the above problem by identifying 5Ws in the problem statement as given
below:
 What: List of marks of students in two subjects physics and mathematics.
 Who: Students.
 Why: To prepare the marks list in descending order (top marks to bottom marks) and
to identify top 5% students of both subject and students having more than 90% marks
in both subjects.
 When: Within a class time. (Approx 40 minutes)
 Where: School.
Activity 1.2 (A.B)
Your task is to find average height of your class fellows. Give a candid answer and also the
method to find the exact solution.
One method is to use a measuring tape. Mark the height on the tape and then read the exact
measurement from the tape. After recording the height of every student, you can calculate the
average height of all the students in your classroom.
Or you can even find out the candid height of a student through some object of known height,
like a book. Let's say that the height of your textbook is 8cm. You can mark the height of the
book on a wall. Using the book several times, you can make a scale with intervals of 8cm.
Then, by standing next to the wall you can get a candid solution to the student's height.
SOLUTION
Method 1: (Candid Answer)
We can find out the candid height of a student through some object of known height, like a book.
Let's say that the height of textbook is 8cm. You can mark the height of the book on a wall.
Using the book several times, you can make a scale with intervals of 8cm. Then, by standing
next to the wall we can get a candid solution to the student's height.
Suppose there are 30 students in a class. We use a book or scale to mark on the wall and then
make three to four students stand against the wall and measure their height. The measurement of
heights of these students are 54, 58, 55 and 56. According to these measurements we
assume that average of all boys in the class is 55. This is a candid solution.
Candid solution: 55
Method 2: (Exact Solution)
To find out the exact solution, we use a measuring tape.
Suppose there are only three students in a class. Mark the height on the tape and then read the
exact measurement from the tape.

COMPUTER SCIENCE-9 10
Unit– 1 Problem Solving
Student Height
1 54
2 58
3 56
Total 166
After recording the height of every student, we calculate the average height of all the
students in classroom by the following formula:

So, the exact solution: 56


Note: we can calculate exact height of 30 students by applying the same technique.
1.2 FLOWCHARTS
LONG QUESTIONS
Q.1 Define flowchart. Write the importance of flowchart in problem solving. (K.B+U.B)
Ans: FLOWCHARTS
Definition:
A flowchart is a graphical presentation of the steps to solve a problem.
IMPORTANCE OF FLOWCHARTS IN PROBLEM SOLVING
The importance of flowchart are as follows:
 Flowcharts are helpful to know about the steps used to solve a problem.
 We use symbols for each step, and these symbols are connected with the help of
arrows to show the flow of processing.
 In problem solving, flowcharts can be used to plan a solution.
 If a flowchart is already there, we can quickly understand the way a problem is
solved.
 It is more effective to visualize a solution graphically than a text.
 A graphical representation also makes it effective to verify whether a solution is
correct or not.
 It is also a good way to communicate the solution of a problem to other people.
Q.2 How do you determine requirement for a flowchart. (Ex Q.5) (U.B)
Ans: REQUIREMENTS FOR A FLOWCHART
In a flowchart we use input, output, decision making and processing:
 Inputs: Input means taking data from the user. It is important to know; how many
and what type of inputs are required.
 Processing: A flowchart also contains processing steps. The processing steps are
used for performing calculations and storing the results of calculations. These may
include increasing/decreasing a value, adding/multiplying/dividing two values etc.
 Decision Making: To determine whether a statement is true or false, and taking
appropriate steps accordingly, is called decision making.
 Outputs: Outputs are used to display information and usually this information exhibits
the processed results.

COMPUTER SCIENCE-9 11
Unit– 1 Problem Solving
Figure: Flow from input to output
Q.3 Write a note on flowchart symbols. (K.B+U.B)
Ans: FLOWCHART SYMBOLS
Flowcharts explain a process clearly through symbols and text. They use special shapes
to represent different types of actions or steps in a process.
Some widely used symbols in flowcharts are as follows:
Symbol Name Description
 Flow line It is used to determine the flow of steps in a flowchart.

Terminal It indicates start and end of a flowchart.

Process It represents operations to change values.

It shows a conditional operation that determines which one of


Decision the two paths to take. The operation is commonly a yes/no
question or a true/false test.
It indicates the input of data from user or displaying results to
Input / Output
user.
If a flowchart doesn't fit on a page, then we use connector to
Connector
connect parts of a flowchart on different pages.
Q.4 Draw a flowchart to display the larger one out of the three given unequal numbers.
(A.B)
Ans: FLOWCHART

COMPUTER SCIENCE-9 12
Unit– 1 Problem Solving
Following flowchart shows another solution to find a maximum value among three number
a,b and c.

Q.5 Draw a flowchart to assign grade to a subject based on total marks and obtained
marks.
(A.B)
Ans: FLOWCHART

COMPUTER SCIENCE-9 13
Unit– 1 Problem Solving

Q.6 Draw a flowchart to determine name of a week day from a given number where
weekdays are assumed from Monday to Sunday and their respective. (A.B)
Ans: FLOWCHART

COMPUTER SCIENCE-9 14
Unit– 1 Problem Solving

COMPUTER SCIENCE-9 15
Unit– 1 Problem Solving
Q.7 Draw a flowchart to input 5 value one by one and determine if the given value is odd or
even.
(A.B)
Ans: FLOWCHART

Q.8 Draw a flowchart to find a sequence of odd numbers starting from a given number till
some limit. (A.B)
Ans: FLOWCHART

COMPUTER SCIENCE-9 16
Unit– 1 Problem Solving

SHORT QUESTIONS
Q.1 Define flowchart. (K.B)
Ans: FLOWCHART
Definition:
A flowchart is a graphical presentation of the steps to solve a problem.
Q.2 What is the importance of flowchart? (K.B)
Ans: IMPORTANCE OF FLOWCHART
The importance of flowchart are as follows:
 Flowcharts are helpful to know about the steps used to solve a problem.
 In problem solving, flowcharts can be used to plan a solution.
Q.3 What is meant by input/output? (K.B)
Ans: INPUT/OUTPUT

Input/Output:
It indicates the input of data from user or displaying results to user.
Q.4 What is meant by processing in flowchart? (K.B)
Ans: PROCESSING
A flowchart also contains processing steps. The processing steps are used for performing
calculations and storing the results of calculations. These may include increasing / decreasing
a value, adding / multiplying / dividing two values etc.
Symbol:
The following symbol is used for processing.

Q.5 What is the purpose of symbol? (K.B)


Ans: DECISION MAKING
The purpose of symbol to determine whether a statement is true or false, and
COMPUTER SCIENCE-9 17
Unit– 1 Problem Solving
taking appropriate steps accordingly. it is called decision making symbol.
It shows a conditional operation that determines which one of the two paths to take. The
operation is commonly a yes/no question or a true/false test.
Q.6 Draw a flowchart to convert Celsius to Fahrenheit temperature. (A.B)
Ans: FLOWCHART

Q.7 Draw a flowchart to find acceleration of a moving object with given mass and force
applied. (A.B)
Ans: FLOWCHART

Q.8 Draw a flowchart to find the volume of a cube. (A.B)


Ans: FLOWCHART

COMPUTER SCIENCE-9 18
Unit– 1 Problem Solving

Q.9 Draw a flowchart to find plain the interest on an amount. (A.B)


Ans: FLOWCHART

Q.10 Draw a flowchart to find the sum, product and average of five given numbers. (A.B)
Ans: FLOWCHART

Q.11 Draw a flowchart to find the area of a parallelogram. (A.B)


Ans: FLOWCHART

COMPUTER SCIENCE-9 19
Unit– 1 Problem Solving

Q.12 Draw a flowchart to determine whether a given number is odd or even. (A.B)
Ans: FLOWCHART

MULTIPLE CHOICE QUESTIONS


1. Pictorial representation of the steps to solve a problem is: (K.B)
(A) Algorithm (B) Flowchart (C) Map (D) design document
2. Flowcharts are designed with the help of: (K.B)
(A) Symbols (B) Picture (C) Lines (D) None of these

3. Symbol of flowchart represents: (K.B)


(A) Processing (B) Decision making (C) Computation (D) Calculation
4. A symbol used in flow chart for both input and output functions: (K.B+U.B)
(A) Parallelogram (B) Rectangle (C) Diamond (D) Oval
5. Flow lines is denoted by symbol: (K.B+U.B)

(A) (B) (C) (D)


COMPUTER SCIENCE-9 20
Unit– 1 Problem Solving
6. Symbol of processing is: (K.B)

(A) (B) (C) (D)


7. _____ is symbol is used to start/end the program: (K.B)

(A) (B) (C) (D)

8. symbol represent in flowchart: (K.B)


(A) Processing (B) Input/Output (C) Connector (D) branching
9. ________ symbol used to show connection in flowchart: (K.B)

(A) (B) (C) (D)


10. The rectangle symbol in flowchart indicates: (K.B+U.B)
(A) Processing (B) Condition (C) Input (D) Output
11. In a flow chart parallelogram symbol represents: (K.B+U.B)
(A) Decision making (B) Input/Output (C) Remarks (D) Processing

COMPUTER SCIENCE-9 21
Unit– 1 Problem Solving

ACTIVITY QUESTIONS
Activity 1.3 (A.B)
Investigate both the approaches presented to find a maximum value among three numbers and
compare them. Which approach has advantage(s) over the other? Write your findings and
discuss with your class teacher.
Flowchart 1 Flowchart 2

SOLUTION
Purpose
Both the flowcharts find the greatest number out of 3 input numbers .
Better (advantage over other)
Flowchart 2 is better.
Reasons (Findings)
while 2nd flowchart does not do this. It
The first flowchart declares the n0 (first number) as
does direct and simple comparison
greater and saves it in a variable (Large) and after
so
that starts comparing itself with the other two
For both these two reasons the above
numbers
flowchart is better in performance
So it is complex and consumption of space.
and memory consumption.

COMPUTER SCIENCE-9 22
Unit– 1 Problem Solving
Activity 1.4 (A.B)
In the following flowchart, a user is supposed to provide the input value from 1 to 7, but it is
possible that the input value is less than 1 or more than 7. We need to take care of such values
and display appropriate messages, like “Your value is less than 1” or “Your value is more than
7”. Modify the flowchart with respect to proper error messages.
To determine name of a week day from a given number where weekdays are assumed
from Monday to Sunday and their respective.

COMPUTER SCIENCE-9 23
Unit– 1 Problem Solving
SOLUTION

Print “Wrong
Day”

1.3 ALGORITHMS
LONG QUESTIONS
Q.1 Define algorithm and argue on its role and importance in problem solving. (Ex Q.3) (K.B)
Ans: ALGORITHM
Definition:
An algorithm is a set of steps to solve a problem. It is written in a natural language, so it
is easily understandable by humans.
Example:
To solve the problem of preparing tea, we can follow the following steps.
 Start.
 Take a kettle.
 Pour water in it.
 Put the kettle on fire.
COMPUTER SCIENCE-9 24
Unit– 1 Problem Solving
 Add sugar and milk.
 Wait till it boils.
 Remove the kettle from fire.
 End.
The above set of steps can be called an algorithm for tea preparation.
ROLE OF ALGORITHMS IN PROBLEM SOLVING
An algorithm has a vital role in problem solving as it provides a step-by-step guide to the
problem solver as follows:
 It is a complete description of the solution.
 Usually a computer programmer first writes an algorithm and then translates it into
the code of some programming language.
 Sometimes, the designer of the program first makes a flowchart to solve a problem
and then encodes the flowchart into an algorithm.
The following figure shows the role of algorithm in problem solving.

Figure: Role of Algorithm


Q.2 Explain formulation of an algorithm. (K.B+U.B)
Ans: FORMULATION OF AN ALGORITHM
There are different notations (keywords) to write an algorithm as in table:
Notation Meaning
It is the starting point of an algorithm. Every algorithm must have one starting
Start (entry) point.
It is used to get input from a user and store it in computer memory with some
Input name.
It is used to give name to data in computer memory. It is also used to update
Set the value of existing data.
It is used to check the condition. For example, the condition like if (a<b). A
condition is evaluated as true or false. In case the condition is true then the
statements related with if part are executed otherwise the statements of else
If, Else part are executed.
Usage: Suppose a=5 and b=7, if (a<5) Set c to l0 else Set c to 20.
Writing else part is optional.
It is used to transfer control to a certain step of an algorithm. It is usually
Goto required in loops.
Output It is used to display values.
Stop It is the termination point of an algorithm.
Q.3 Explain efficiency of algorithms with example.
OR
Suppose a problem has multiple algorithms. How would you choose the most efficient
one? Explain with examples. (Ex Q.4) (K.B+U.B)
Ans: EFFICIENCY OF ALGORITHMS
There can be more than one algorithm to solve the same problem. Which one is better,
depends upon the efficiency of the available solution algorithms. Efficiency of an
algorithm is measured on the basis of two metrics as follows:
COMPUTER SCIENCE-9 25
Unit– 1 Problem Solving
1- Number of steps:
An algorithm is considered more efficient if it takes less number of steps to reach the results.
2- Space used in computer memory:
We have observed in algorithms that some data is stored in computer memory which is
latter used to give results. An algorithm using less space in computer memory is
considered more efficient with respect to memory space.
Explanation:
It is quite possible that one algorithm takes less space in memory and has more number of
steps whereas the other algorithm takes more memory and has less number of steps. In
this case there is a trade-off between number of steps and the consumed memory. The
designer can take decision according to the requirements.
Example 1:
Let's suppose we have two algorithms to solve a certain problem. One algorithm has N
steps whereas the other algorithm has N2 steps. In this case the former algorithm is
considered more efficient than the latter one.
Example 2:
We need to compute the following.
1 + 2 + 3 + 4 + 5 + … + 99
How can we find its answer?
Solution1:
Different minds can find different solutions to solve this problem. One solution is to start
adding numbers from beginning and keep adding till the end.
Solution2:
Other solution is to start making pairs as (1 + 99), (2 + 98), (3 + 97), (4 + 96), (5 + 95) ...
(49,51) where each pair gives answer 100. We count the number of pairs and multiply
that count with 100 and then in the result we add 50 as it is nowhere in any pair.
Solution3:
n  n  1
Another solution is to use formula where n is the last term. So, the solution is
2
99  99  1
just to solve .
2
This example shows different approaches to solve one problem and if these approaches are
used in computer then accordingly there may be different memory usage and number of
steps.
Q.4 Explain the differences between algorithm and flowchart. (K.B+U.B)
Ans: DIFFERENTIATION
Difference between an algorithm and a flowchart is just like the difference between a
story and a movie.
Flowchart Algorithm
A flowchart is a graphical representation of An algorithm writes the same steps in a
the process to solve a problem. human understandable language.
It is easy to draw. It is easy to write.
The techniques to write an algorithm are easy
It is easy to understand problem solving.
to understand.
The usage of Goto makes it difficult to
It is easy to identify errors (if any).
identify errors.
It makes easy to observe flow from one step to It is not very easy to show the flow from one
the other. step to the other.
Modifying a flowchart is very difficult every Modifying an existing algorithm is easy as
time. compared flowchart.
More time is required to draw a flowchart. Less time is required to draw an algorithm.

COMPUTER SCIENCE-9 26
Unit– 1 Problem Solving
It is not suitable for very large problems. To solve a large problem, algorithms are helpful.
SHORT QUESTIONS
Q.1 Define algorithm. Also make an algorithm for preparing tea. (K.B+U.B+A.B)
Ans: ALGORITHM
Definition:
An algorithm is a set of steps to solve a problem. It is written in a natural language, so it
is easily understandable by humans.
Algorithm for Making Tea:
To solve the problem of preparing tea, we can follow the following steps:
 Start.
 Take a kettle.
 Pour water in it.
 Put the kettle on fire.
 Add sugar and milk.
 Wait till it boils.
 Remove the kettle from fire.
 End.
Q.2 Write some advantages of flowchart. (K.B)
Ans: ADVANTAGES OF A FLOWCHART
Advantages of a flowchart are as follows:
 It is easy to draw.
 It is easy to understand problem solving.
 It is easy to identify errors (if any).
 It makes easy to observe flow from one step to the other.
Q.3 Write some disadvantages of flowchart. (K.B)
Ans: DISADVANTAGES OF A FLOWCHART
Disadvantages of a flowchart are as follows:
 More time is required to draw a flowchart.
 Modifying a flowchart is not very easy every time.
 It is not suitable for very large problems.
Q.4 Write some advantages of algorithm. (K.B)
Ans: ADVANTAGES OF AN ALGORITHM
Some advantages of an algorithm are as follows:
 It is easy to write.
 Techniques to write an algorithm are easy to understand.
 To solve a large problem, algorithms are helpful.
Q.5 Write some disadvantages of algorithm. (K.B)
Ans: DISADVANTAGES OF AN ALGORITHM
Some disadvantages of an algorithm are as follows:
 Modifying an existing algorithm is not very easy every time.
 Showing the flow from one step to the other is not very easy.
 Usage of Goto makes it difficult to identify errors.
Q.6 What is the use of „set‟ in writing algorithms? (K.B+U.B)
Ans: USE OF SET
It is used to give name to data in computer memory. It is also used to update the value of
COMPUTER SCIENCE-9 27
Unit– 1 Problem Solving
existing data.
Q.7 Write an algorithm to find the sum, product and average of five given numbers.
(A.B)
Ans: ALGORITHM
Step 1. Start
Step 2. Input numbers, n0, n1, n2, n3, n4
Step 3. Set sum to n0 + n1 + n2 + n3 + n4
Step 4. Set product to n0 × n1 × n2 × n3 × n4
n 0  n1  n 2  n 3  n 4
Step 5. Set average to
5
Step 6. Output sum, product, average
Step 7. End
Q.8 Write an algorithm to find acceleration of a moving object with given mass and the
applied force. (A.B)
Ans: ALGORITHM
Step 1. Start
Step 2. Input numbers, mass, force
force
Step 3. Set acceleration to
mass
Step 4. Output acceleration
Step 5. End
Q.9 Write an algorithm to find the volume of a cube. (A.B)
Ans: ALGORITHM
Step 1. Start
Step 2. Input number, side
Step 3. Set volume to side × side × side.
Step 4. Output volume
Step 5. End
Q.10 Write an algorithm to find the area of a parallelogram. (A.B)
Ans: ALGORITHM
Step 1. Start
Step 2. Input numbers, base, height
Step 3. Set area to base × height
Step 4. Output area
Step 5. End
Q.11 Write an algorithm to display the larger one out of the three given numbers. (A.B)
Ans: ALGORITHM
Step 1. Start
Step 2. Input numbers, n0, n1, n2
Step 3. Set large to n0
Step 4. if nl > large Set large to nl
Step 5. if n2 > large Set large to n2
Step 6. Output large
Step 7. End

COMPUTER SCIENCE-9 28
Unit– 1 Problem Solving
Q.12 Write an algorithm to assign grade to a subject based on the achieved marks. (A.B)
Ans: ALGORITHM
Step 1. Start
Step 2. Input numbers, obtained_marks, total_marks
obtained _marks
Step 3. Set percentage to 100
total _marks
Step 4. if percentage > 80 Set grade to A +
else
if percentage > 70 Set grade to A
else
if percentage > 60 Set grade to B
else
if percentage > 50 Set grade to C
else
if percentage > 40 Set grade to D
else
if percentage > 33 Set grade to E
else
Set grade to F.
Step 5. Output grade
Step 6. End
Q.13 Write an algorithm to find the interest on an amount. (A.B)
Ans: LGORITHM
Step 1. Start
Step 2. Input numbers, amount, rate, years
 rate 
Step 3. Set plain_interest to  amount    years
 100 
Step 4. Output plain_interest
Step 5. End
Q.14 Write an algorithm to convert Celsius to Fahrenheit temperature and vice versa. (A.B)
Ans: ALGORITHM
Step 1. Start
Step 2. Input number, Celsius
celsius  9
Step 3. Set fahrenheit to  32
5
Step 4. Output fahrenheit
Step 5. Input number, fahrenheit
5
Step 6. Set Celsius to (fahrenheit –32) 
9
Step 7. Output Celsius
Step 8. End

COMPUTER SCIENCE-9 29
Unit– 1 Problem Solving
Q.15 Write an algorithm to find even numbers in integers ranging from n1 to n2 (where
n2 is greater than n1). (A.B)
Ans: ALGORITHM
Step 1. Start
Step 2. Input numbers, n1, n2
Step 3. if (n1< n2) {
Step 4. if (n1 mod 2 equal 0) Output n1
Step 5. Set n1 to n1+1
Step 6. go to Step 3
}
Step 7. End
Q.16 How can we measure the efficiency of algorithms? (U.B)
Ans:
EFFICIENCY OF AN ALGORITHM

Efficiency of an algorithm is measured on the basis of two metrics as follows:


1- Number of steps: An algorithm is considered more efficient if it takes less number of
steps to reach the results.
2- Space used in computer memory: We have observed in algorithms that some data is
stored in computer memory which is latter used to give results. An algorithm using
less space in computer memory is considered more efficient with respect to memory
space.
MULTIPLE CHOICE QUESTIONS
1. The steps to solve a problem is called: (K.B+U.B)
(A) Algorithm (B) Flowchart (C) Map (D) Design
2. Algorithm is written in which language? (K.B)
(A) Urdu (B) Natural (C) Programming (D) Binary
3. Algorithm include: (K.B+U.B)
(A) Input (B) Processing (C) Output (D) All of these
4. The word "algorithm" comes from the name of Arabic writer: (Do you know page no. 16) (K.B)
(A) Abu Qasim (B) Al Beroni
(C) Jabar bin Hayan (D) Muhammad ibn Musa al-Khwarizmi
5. The starting point of an algorithm is: (K.B)
(A) Start (B) Input (C) Set (D) Output
6. Which one is used to give name to data in computer memory? (K.B+U.B)
(A) Start (B) Input (C) Set (D) Output
7. Which one is required for loops? (K.B)
(A) Start (B) Goto (C) Set (D) Output
8. The termination point of an algorithm is: (K.B)
(A) Start (B) Goto (C) Set (D) Stop
9. Efficiency of an algorithm is measured on the basis of: (U.B)
(A) 1 metric (B) 2 metrics (C) 3 metrics (D) 4 metrics
10. Let's suppose we have two algorithms to solve a certain problem. One algorithm has
N steps whereas the other algorithm has N2 steps. In this case which is more
efficient? (U.B+A.B)
(A) First algorithm (B) Second algorithm (C) Both (D) None
11. How many squares are on chess board? (Do you know page no. 23) (K.B+U.B)
(A) 100 (B) 80 (C) 64 (D) 50

COMPUTER SCIENCE-9 30
Unit– 1 Problem Solving

COMPUTER SCIENCE-9 31
Unit– 1 Problem Solving

ACTIVITY QUESTIONS
Activity 1.6 (A.B)

The Figure shows a simple example of calculating


average of three numbers, 25, 45 and 65. Write an
algorithm with these fixed values to calculate and
display average values. Note that in this case no
input is required from a user.

Example of calculating Average


SOLUTION
Step 1. Start
Step 2. Set a to 25
Step 3. Set b to 45
Step 4. Set c to 65
Step 5. Set average to
Step 6. Output average
Step 7. End
Activity 1.7 (A.B)
Change the algorithm for finding volume of a Cylinder and Sphere. The formula for the volume of
4
a Sphere is   r 3 where r is radius. The formula for the volume of cylinder is  r 2h where r is
3
radius and h is height.
To find the volume of a cube.
Step 1. Start
Step 2. Input number, side
Step 3. Set volume to side × side × side.
Step 4. Output volume
Step 5. End
SOLUTION
Step 1. Start
Step 2. Input radius
Step 3. Set pi() to 3.1415
Step 4. Set volume_sphere to
Step 5. Output volume_sphere
Step 6. Input height
Step 7. Set volume_cylinder to
Step 8. Output volume_cylinder
Step 9. End

COMPUTER SCIENCE-9 32
Unit– 1 Problem Solving
Activity 1.8 (A.B)
Change the algorithm for finding the area of a triangle, rhombus, or trapezium.
To find the area of a parallelogram.
Step 1. Start
Step 2. Input numbers, base, height
Step 3. Set area to base × height
Step 4. Output area
Step 5. End
SOLUTION
Area of a Triangle:
Step 1. Start
Step 2. Input base, height
Step 3. Set area to base × height
Step 4. Output area
Step 5. End
Area of a Rhombus:
Step 1. Start
Step 2. Input d1, d2
Step 3. Set area to
Step 4. Output area
Step 5. End
Area of a Trapezium:
Step 1. Start
Step 2. Input a, b, height
Step 3. Set area to (a + b) × height
Step 4. Output area
Step 5. End
Activity 1.9 (A.B)
Compare the algorithm 9 presented in Section 1.3.4 with the following one and try to find
which one is efficient. Note that both are solving the same problem. In order to answer this
question, assume two values for nl and n2 and start count the number of steps used in both
algorithms.
Algorithm 1.9 Algorithm 9 (Section 1.3.4)
Step 1. Start Step 1. Start
Step 2. Input numbers, nl, n2 Step 2. Input numbers, n1, n2
Step 3. if nl is odd, set nl to nl + 1 Step 3. if (n1< n2) {
Step 4. Output nl Step 4. if (n1 mod 2 equal 0) Output n1
Step 5. Set nl to nl + 2 Step 5. Set n1 to n1+1
Step 6. if nl < n2 go to Step 4 Step 6. go to Step 3
Step 7. End }
Step 7. End
SOLUTION
Steps In the above algorithm (algorithm 1.9) In the above algorithm (algorithm 9)
Step 1. Algorithm starts. Algorithm starts.
Step 2. It inputs two numbers n1(starting value) It inputs two numbers n1(starting value)
COMPUTER SCIENCE-9 33
Unit– 1 Problem Solving
and n2(ending value). and n2(ending value).
Step 3. If n1 is odd, it increments 1 into n1 to It checks if n1 is less than n2 or not.
convert n1 into an even number.
Step 4. It displays n1 i.e. it displays first evenIt checks if n1 is even or not.
number. If n1 is even then display n1 as a first
even number.
Step 5. It increments 2 in n1. (jump to next even It increments 1 in n1. (jump to next
number) number)
Step 6. It repeats itself until the ending value. It repeats itself until the ending value.
(Step 4, 5, 6 is repeated) to display only (Step 3, 4, 5, 6 is repeated) to check if it
even number. is even or not and then display even
number.
Step 7. Algorithm ends. Algorithm ends.
So, Algorithm used in activity 1.9 is more efficient because it is very easy and uses less
number of steps.
1.4 TEST DATA
LONG QUESTIONS
Q.1 Describe the importance of testing. (K.B+U.B)
Ans: IMPORTANCE OF TESTING
Testing is essential to point out the defects and errors made during finding a solution to
some problem. It helps in improving a solution. If one solves a problem and someone else
uses that solution for commercial purposes, then the commercial activities depend upon
the correctness of that solution.
Example 1:
If we develop a solution for finance management and some bank starts using it then any
error in that solution may result in a financial loss. So, testing is important for a solution.
Example 2:
A car is delivered to a customer after testing. Upon launching a new car, it is usually
tested with a robot driver who hits the car with a wall. It is used to test whether the air
bags and other security systems are functioning or not. Moreover, it also allows the car
designers to suggest further security measures to reduce the damage. This test can help to
make a car safe. So, testing helps to improve quality.
Q.2 Explain types of test data. (Ex Q.6) (K.B)
Ans: TEST DATA
Definition:
After solving a problem, we need to test whether the solution is correct or not, and for
testing, we need “Test Data”.
TYPES OF TEST DATA
Creation of proper and sufficient test data is one of the key activities to improve quality
of a solution. Each type of solution requires different data.
Types of Test Data include:
 Valid test data
 Invalid test data
 Boundary test data values
 Wrong data formats
 Absent data
COMPUTER SCIENCE-9 34
Unit– 1 Problem Solving

COMPUTER SCIENCE-9 35
Unit– 1 Problem Solving
Valid Test Data:
It is the test data that complies with the input requirements of the algorithm. If an
algorithm is supposed to take a numeric value between 1 and 100 as input, then any value
between 1 and 100 is a valid test data.
Invalid Test Data:
It is the data that does not comply with the input requirements of the algorithm. It is
necessary to make sure that the solution correctly works for invalid values, shows the
relevant messages notifying the user that the provided input values are improper.
Boundary Test Data Values:
A solution is tested on extreme values. For example, to calculate interest we can consider
principal amount as 0 or a very huge amount.
Wrong Data Formats:
It is wise to check how the system reacts on entering data in an inappropriate format. For
example, giving an alphabet as input when a numeric value is expected.
Absent data:
It is also important to investigate that the solution still works if less number of inputs are
given than expected. For example, if a system asks to enter driving license number, then
every one cannot provide this information. It is important to see how the system reacts in
such situations.
SHORT QUESTIONS
Q.1 Define test data. (K.B)
Ans: TEST DATA
Definition:
After solving a problem, we need to test whether the solution is correct or not, and for
testing, we need “Test Data”.
Example:
If we want to test the algorithm to find the largest among three given numbers n0, n1 and
n2, then we need three values. These values can be positive, negative or zero, e.g., (n0 =
5, n1 = 15, n2 = 3), (n0 = 27, n1 = –6, n2 = 35), (n0 = 24, n1 = 0, n2 = 11), etc. So, for
thinking about testing, we also need to think about test data.
Q.2 Name the types of test data. (K.B+U.B)
Ans: TYPES OF TEST DATA
Creation of proper and sufficient test data is one of the key activities to improve quality
of a solution. Each type of solution requires different data.
Types of Test Data include:
 Valid test data
 Invalid test data
 Boundary test data values
 Wrong data formats
 Absent data
Q.3 Differentiate between valid test data and invalid test data. (U.B)
Ans: DIFFERENTIATE
The difference between valid and invalid test data is as follows:
Valid Test Data Invalid Test Data
It is the test data that complies with the input It is the test data that does not comply with
requirements of the algorithm. the input requirements of the algorithm.
If an algorithm is supposed to take a numeric It is necessary to make sure that the solution
value between 1 and 100 as input, then any correctly works for invalid values, shows the
value between 1 and 100 is a valid test data. relevant messages notifying the user that the
provided input values are improper.
COMPUTER SCIENCE-9 36
Unit– 1 Problem Solving

MULTIPLE CHOICE QUESTIONS


1. After solving a problem, we need to test whether the solution is correct or not, and
for testing, we need “____________”. (K.B+U.B)
(A) Algorithm (B) Flowchart (C) Test data (D) Design
2. Types of test data are: (K.B)
(A) 2 (B) 4 (C) 5 (D) 6
3. A solution is tested on extreme values is called: (K.B)
(A) Valid Test Data (B) Invalid Test Data
(C) Wrong Data Formats (D) Boundary Test Data Values
4. A test data which complies with input requirements: (K.B+U.B)
(A) Valid Test Data (B) Invalid Test Data
(C) Wrong Data Formats (D) Boundary Test Data Values
5. A test data which does not comply with input requirements: (K.B+U.B)
(A) Valid Test Data (B) Invalid Test Data
(C) Wrong Data Formats (D) Boundary Test Data Values
ACTIVITY QUESTIONS
Activity 1.10 (A.B)
Assume that you are given an automatic
attendance system for testing. In this system,
a camera observes each student entering in
the classroom. The camera is connected to a
computer which contains the database of
pictures of all the students. The solution
compares each student with the pictures in
database and mark the attendance is picture is
found there. You are asked to provide test
data for the system. Write your points in a
way that can help the solution provider to
check and improve quality of the solution. You can think about different dresses in different
weathers, identical twins, different haircuts or any other points where one can look different in
front of camera.
SOLUTION
The following test data will be provided to system in order to check the performance and
accuracy of the system:
 The students will be dressed in different clothes (winter and summer uniform) along
with cap or without cap, with face mask or without face mask, glasses or without
glasses.
 Moreover, the looks of students will be changed with haircut and without haircut and
also by wearing school bag or without school bag.
 Students will have to stand in front of camera while smiling or without smiling.
 Similarly, students will be standing in different poses in front of camera.
 In case of twins, their thumb recognition will be required.

COMPUTER SCIENCE-9 37
Unit– 1 Problem Solving

1.5 VERIFICATION AND VALIDATION


LONG QUESTIONS
Q.1 Describe verification and validation with examples. (K.B+U.B)
Ans: VERIFICATION AND VALIDATION
Verification:
Verification means to test if the solution is actually solving the same problem for which it
was designed.
Example:
If you are asked to give a solution for calculating compound interest then verification
means to know that it is giving results for compound interest not for the plain interest.
Validation:
Validation means to test whether the solution is correct or not.
For example, if you are asked to give a solution for calculating compound interest then
validation means to know whether it is finding the correct compound interest or not. If a
solution is verified, then it is validated with the help of test data.
Example 1:
Let‟s assume that you go to a pizza shop and order a chicken pizza. You state your
requirement that it should be less spicy. You also expect that it would taste good. When
the pizza arrives, you can observe that it is a chicken pizza. This is called verification.
Now, when you eat the pizza, you can check whether it is less spicy or not, it tastes good
or not. This is called validation.
Example 2:
Let‟s assume that you are asked to write an algorithm that takes as input a list of
numbers. The algorithm should display the list arranged in ascending order. After writing
the algorithm you submit it to your teacher. Your teacher provides a list of numbers to the
algorithm. If your algorithm displays a list of numbers then it is verified. Instead if your
algorithm displays an answer in yes or no, or displays something else, then it is not
verified. If your algorithm is verified, your teacher moves to the next step of validation.
He checks whether the list of numbers displayed are actually in ascending order or not. If
the list is in ascending order and no element is missing then your solution is also
validated.
SHORT QUESTIONS
Q.1 What is difference between verification and validation. (K.B+U.B)
Ans: DIFFERENTIATE
The difference between valid and invalid test data is as follows:
Verification Validation
Definition
Verification means to test if the solution is Validation means to test whether the solution
actually solving the same problem for which it is correct or not.
was designed.
Example
If you are asked to give a solution for If you are asked to give a solution for calculating
calculating compound interest then compound interest then validation means to
verification means to know that it is giving know whether it is finding the correct compound
results for compound interest not for the plain interest or not. If a solution is verified, then it is
interest. validated with the help of test data.

COMPUTER SCIENCE-9 38
Unit– 1 Problem Solving

MULTIPLE CHOICE QUESTIONS


1. To test if the solution is actually solving the same problem for which it was designed
means: (K.B+U.B)
(A) Design (B) Verification (C) Validation (D) Reservation
2. To test whether the solution is correct or not means: (K.B+U.B)
(A) Design (B) Verification (C) Validation (D) Reservation
1.6 IDENTIFICATION AND CORRECTION OF ERRORS
LONG QUESTIONS
Q.1 Write a note on trace table. (Ex Q.7) (K.B+U.B)
Ans: TRACE TABLE
Definition:
A trace table is a technique used to test algorithms, in order to make sure that no logical
errors occur while the algorithm is being processed.
Explanation:
The table usually takes the form of a multi-column, multi-row table; with each column
showing names of data, and each row showing values of the data at each step.
Example:
To recruit students for our school volleyball team, we need students having height
between 144 cm and 164 cm. To count qualified students, we develop the following
algorithm.
Step 1. Start
Step 2. Set count to 0
Step 3. Set all_heights to [154, 140, 155, 164, 144, 166, 160, 143]
Step 4. For each height in the list all_heights
Step 5. If height > 144 and height  164 then Set count to count + 1
Step 6. Output count
Step 7. Stop
We can make a trace table for the above algorithm:
In the following table, the blank means there is no change and -- means that a value is not
concerned. In the following table Step 1 has no effect on data. Step 2 is assigning 0 to
count and in Step 3, list all_heights is introduced. In Step 4, there is no change in both
count and all-heights but the data 154 is stored in height. It is compared in Step 5 and the
value in count is updated if data is in given range. Steps 4 and 5 are repeated for each
value.
count All heights
Step 1 -- --
Step 2 0 -- --
Step 3 [154, 140, 155, 164, 144, 166, 160, 143]
Step 4 154
Step 5 1
Step 4 140
Step 5 1
Step 4 155

COMPUTER SCIENCE-9 39
Unit– 1 Problem Solving
Step 5 2
Step 4 164
Step 5 3
Step 4 144
Step 5 3
Step 4 166
Step 5 4
Step 4 160
Step 5 5
Step 4 143
Step 5 5
Step 6
Step 7
SHORT QUESTIONS
Q.1 Why we use trace table? (U.B)
Ans: TRACE TABLE
A trace table is a technique used to test algorithms, in order to make sure that no logical
errors occur while the algorithm is being processed.
Q.2 Why we use invalid data for testing? (U.B)
Ans: INVALID DATA FOR TESTING
Testing an algorithm using invalid data ensures that the algorithm can gracefully handle
unexpected data inputs. If an algorithm requires your age in number of days but you give
date of birth as input then the algorithm may not work properly. The purpose of testing
using invalid test data is to detect such situations. In this case error messages are shown
as output. Moreover, this kind of testing helps you to improve the quality of solution.
MULTIPLE CHOICE QUESTIONS
1. The solution is working but not giving required results. This type of error is called:
(K.B+U.B)
(A) Syntax Error (B) Runtime Error (C) Logical Error (D) Random Error
2. A technique used to test algorithms is: (K.B+U.B)
(A) Design (B) Trace Table (C) Validation (D) Correctness
ACTIVITY QUESTIONS
Activity 1.11 (A.B)
Write all the above discussed algorithms keeping in mind the invalid test data inputs. Class teacher
may divide class in few groups and assign them one or more algorithm(s). Students are supposed to
discuss and rewrite algorithms so that upon invalid inputs, appropriate messages are displayed.
SOLUTION
Algorithm 1
To find the sum, product and average of five given numbers.
Original Apply Test Data
Step 1. Start Step 1. Start
Step 2. Input numbers, n0, n1, n2, n3, n4 Step 2. Input numbers, n0, n1, n2, n3, n4
Step 3. Set sum to n0 + n1 + n2 + n3 + n4. Step 3. If (n0, n1, n2, n3, n4 are positive
Step 4. Set product to n0 × n1 × n2 × n3 × n4 integers) goto step 4
else print “Invalid input, Enter only

COMPUTER SCIENCE-9 40
Unit– 1 Problem Solving

n 0  n1  n 2  n 3  n 4 positive numbers” goto step 2


Step 5. Set average to Step 4. Set sum to n0 + n1 + n2 + n3 + n4.
5 Step 5. Set product to n0 × n1 × n2 × n3 × n4
Step 6. Output sum, product, average
n 0  n1  n 2  n 3  n 4
Step 7. End Step 6. Set average to
5
Step 7. Output sum, product, average
Step 8. End
Algorithm 2
To find acceleration of a moving object with given mass and the applied force.
Original Apply Test Data
Step 1. Start Step 1. Start
Step 2. Input numbers, mass, force Step 2. Input numbers, mass, force
force Step 3. If (mass, force is positive integer)
Step 3. Set acceleration to goto step 4
mass
else print “Invalid input, Enter only
Step 4. Output acceleration
positive numbers” goto step 2
Step 5. End
Step 4. if (mass is equal to 0) print “cannot
divide by zero” goto step 2
else goto step 5
force
Step 5. Set acceleration to
mass
Step 6. Output acceleration
Step 7. End
Algorithm 3
To find the volume of a cube.
Original Apply Test Data
Step 1. Start Step 1. Start
Step 2. Input number, side Step 2. Input number, side
Step 3. Set volume to side × side × side. Step 3. If (side is positive integer) goto step 4
Step 4. Output volume else print “Invalid input, Enter only
positive numbers” goto step 2
Step 5. End
Step 4. Set volume to side × side × side.
Step 5. Output volume
Step 6. End

Algorithm 4
To find the area of a parallelogram.
Original Apply Test Data
Step 1. Start Step 1. Start
Step 2. Input numbers, base, height Step 2. Input numbers, base, height
Step 3. Set area to base × height Step 3. If (base and height are positive
Step 4. Output area integers) goto step 4
Step 5. End else print “Invalid input, Enter only
positive numbers” goto step 2
Step 4. Set area to base × height
COMPUTER SCIENCE-9 41
Unit– 1 Problem Solving
Step 5. Output area
Step 6. End
Algorithm 5
To display the larger one out of the three given numbers.
Original Apply Test Data
Step 1. Start Step 1. Start
Step 2. Input numbers, n0, n1, n2 Step 2. Input numbers, n0, n1, n2
Step 3. Set large to n0 Step 3. Set large to n0
Step 4. if nl > large Set large to nl Step 4. if nl > large Set large to nl
Step 5. if n2 > large Set large to n2 Step 5. if n2 > large Set large to n2
Step 6. Output large Step 6. Output large
Step 7. End Step 7. End
Algorithm 6
To assign grade to a subject based on the achieved marks.
Original Apply Test Data
Step 1. Start Step 1. Start
Step 2. Input numbers, obtained_marks, Step 2. Input numbers, obtained_marks,
total_marks total_marks
Step 3. Set percentage to Step 3. If (obtained_marks, total_marks are
obtained _marks positive integers) goto step 4
100 else print “Invalid input, Enter only
total _marks
Step 4. if percentage > 80 Set grade to A + positive numbers” goto step 2
else Step 4. if (total_marks is equal to 0) print
if percentage > 70 Set grade to A “cannot divide by zero” goto step 2
else else goto step 5
if percentage > 60 Set grade to B Step 5. Set percentage to
obtained _marks
else 100
if percentage > 50 Set grade to C total _marks
else Step 6. if percentage > 80 Set grade to A +
if percentage > 40 Set grade to D else
else if percentage > 70 Set grade to A
if percentage > 33 Set grade to E else
else if percentage > 60 Set grade to B
Set grade to F. else
Step 5. Output grade if percentage > 50 Set grade to C
Step 6. End else
if percentage > 40 Set grade to D
else
if percentage > 33 Set grade to E
else
Set grade to F.
Step 7. Output grade
Step 8. End
Algorithm 7
To find the interest on an amount.
Original Apply Test Data
COMPUTER SCIENCE-9 42
Unit– 1 Problem Solving
Step 1. Start Step 1. Start
Step 2. Input numbers, amount, rate, years Step 2. Input numbers, amount, rate, years
Step 3. Set plain_interest to Step 3. Set plain_interest to
 rate   rate 
 amount    years  amount    years
 100   100 
Step 4. Output plain_interest Step 4. Output plain_interest
Step 5. End Step 5. End
Algorithm 8
To convert Celsius to Fahrenheit temperature and vice versa.
Original Apply Test Data
Step 1. Start Step 1. Start
Step 2. Input number, Celsius Step 2. Input number, Celsius
celsius  9 celsius  9
Step 3. Set fahrenheit to  32 Step 3. Set fahrenheit to  32
5 5
Step 4. Output fahrenheit Step 4. Output fahrenheit
Step 5. Input number, fahrenheit Step 5. Input number, fahrenheit
5 5
Step 6. Set Celsius to (fahrenheit –32)  Step 6. Set Celsius to (fahrenheit –32) 
9 9
Step 7. Output Celsius Step 7. Output Celsius
Step 8. End Step 8. End
Algorithm 9
Find even numbers in integers ranging from n1 to n2 (where n2 is greater than n1).
Original Apply Test Data
Step 1. Start Step 1. Start
Step 2. Input numbers, n1, n2 Step 2. Input numbers, n1, n2
Step 3. if (n1< n2) { Step 3. if (n1< n2) {
Step 4. if (n1 mod 2 equal 0) Output n1 Step 4. if (n1 mod 2 equal 0) Output n1
Step 5. Set n1 to n1+1 Step 5. Set n1 to n1+1
Step 6. go to Step 3 Step 6. go to Step 3
} }
Step 7. End Step 7. End

COMPUTER SCIENCE-9 43
Unit– 1 Problem Solving

EXERCISE
1.1 Answer the following questions. (U.B)
1. In a farm there are some cows and birds. If there are total 35 heads and110 legs then how
many cows and birds are there?

Ans: SOLUTION
Each cow has 1 head and 4 legs. Each bird has 1 head and 2 legs.
Let x = number of cows and y = number of birds
Then x + y = 35
4x + 2y = 110
Multiply the first equation by –2
– 2x – 2y = – 70
Add the equations
– 2x – 2y = – 70
4x + 2y = 110
Then
2x = 40
Then x = 20
Put this in first equation
20 + y = 35
y = 35 – 20 = 15
So, x = number of cows = 20 and y = number of birds = 15
2. Define problem analysis. Explain your answer along with an example. (K.B+U.B)
See LQ .2 (Topic 1.1)
3. Define an algorithm and argue on its role and importance in problem solving. (K.B+U.B)
See LQ.1 (Topic 1.3)
4. Suppose a problem has multiple algorithms. How would you choose the most efficient
one? Explain with examples. (U.B+A.B)
See LQ.3 (Topic 1.3)
5. How do you determine requirements for a flowchart? (K.B+U.B)
See LQ.2 (Topic 1.2)
6. Explain types of test data. (K.B)
See LQ.2 (Topic 1.4)
7. Describe a trace table. (K.B)
See LQ. (Topic 1.6)
COMPUTER SCIENCE-9 44
Unit– 1 Problem Solving
1.2 Choose the correct option.
1. Which solutions are not reached through proper algorithms or work planning? (U.B)
(i) Prepared solution (ii) Candid solution
(iii)Strategized solution (iv) Best solution
2. __________ is a graphical representation of an algorithm. (K.B)
(i) Matrix (ii) Graph
(iii)Flowchart (iv) Solution
3. Which symbol in the flowchart is used to either start or end the flowchart? (U.B)
(i) Terminal (ii) Connector
(iii)Process (iv) Decision
4. __________ means to test if the required solution is there. (K.B)
(i) Verification (ii) Algorithm
(iii)Validation (iv) Flowchart
5. In a __________error, the solution is working but not giving required results. (K.B)
(i) Random error (ii) Logical error
(iii)Syntax error (iv) Runtime error
ANSWER KEY
1 (ii) 2 (iii) 3 (i) 4 (i) 5 (ii)
1.3 Fill in the blanks.
1. Before problem solving, we need to first_________ a problem. (K.B+U.B)
2. An algorithm produces a defined set of__________. (K.B)
3. A flowchart utilizes various________ and_____to map out the order of steps. (K.B+U.B)
4. In flowcharts symbol  is used to show a_________. (K.B+U.B)
5. _________ is used to test the solutions. (U.B)
ANSWERS
1 Analyse 2 Steps 3 Symbols, text 4 Decision making 5 Verification
1.4 Draw the flowcharts for the following problems. (A.B)
1. Input two numbers nl and n2. Determine whether nl divides n2 or not.
Ans: SOLUTION

COMPUTER SCIENCE-9 45
Unit– 1 Problem Solving
2. Input a year and determine whether it is a leap year or not.
Ans: SOLUTION

3. Input a number and calculate its factorial.


Ans: SOLUTION

COMPUTER SCIENCE-9 46
Unit– 1 Problem Solving
4. Find LCM (Least Common Multiple) of two numbers.
Ans: SOLUTION

5. Input a number and display its factors.


Ans: SOLUTION

COMPUTER SCIENCE-9 47
Unit– 1 Problem Solving
Activity 1.12 (A.B)
Design a flowchart to calculate fine amount for Pakistan motorway. Fine is imposed according
to the following coding scheme. Input a code and display the respective output.
Penalty
Code Offence Imprisonment
(Rs.)
A20 Driving when disqualified 1000 Upto 6 Months
Obtaining or Applying for a driving licence without
A21 500-1000 Upto 6 Months
disclosing particulars of endorsement
A22 Offence relating to construction of vehicle 500-1000 Upto 6 Months
A23 Offence relating to permits 1000-2000 Upto 6 Months
A24 Overloading of goods 15 % in excess of permissible limits. 1000-5000 Upto 1 Month
Overloading of passengers 30 % in excess of permissible
A25 1000-5000 Upto 1 Month
limits
For more codes, visit http://nhmp.gov.pk
Make the flowchart more comprehensive by adding more codes. Make your algorithm on a
chart. Display your chart in your school or community for further awareness on traffic related
crimes and their penalties.
Respective teachers can request school administration to arrange a traffic awareness campaign
for the community. Students can display their charts as part of the campaign.
SOLUTION

COMPUTER SCIENCE-9 48
Unit– 1 Problem Solving

ANSWER KEY
1.1 PROBLEM SOLVING STEPS
1 D 2 B 3 A 4 C 5 A
6 A 7 C 8 B 9 B 10 A
11 C 12 B 13 D 14 C 15 C
1.2 FLOWCHARTS
1 B 2 A 3 B 4 A 5 A
6 D 7 A 8 B 9 C 10 A
11 B
1.3 ALGORITHM
1 A 2 B 3 D 4 D 5 A
6 B 7 B 8 D 9 B 10 A
11 C
1.4 TEST DATA
1 C 2 C 3 D 4 A 5 B
1.5 VERIFICATION AND VALIDATION
1 B 2 C
1.6 IDENTIFICATION AND CORRECTION OF ERRORS
1 C 2 B

COMPUTER SCIENCE-9 49

You might also like