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

Introduction To Problem Solving - CLass Notes

Uploaded by

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

Introduction To Problem Solving - CLass Notes

Uploaded by

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

Introduction to Problem Solving

1. What is problem solving?


Problem solving is the process of identifying a problem, designing a stepwise solution and finally
implementing the solution to ensure the desired outcome.

2. What are the different steps for problem solving?


→ Analyzing the Problem: In this step, we identify the problem precisely to have a clear
understanding.
→ Developing an Algorithm: In this step, we design a stepwise solution for the identified problem.
→ Implementing Code: In this step, we implement the solution using a programming language.
→ Testing and Debugging: In this step, we test our solution (code) for presence of any errors. Then,
we remove the bugs like syntax, logical and runtime errors if found.

3. What is algorithm?
An algorithm is a sequence of a finite number of unique steps to accomplish a task or solve a
problem.

4. What is the purpose of an algorithm?


→ It prepares a roadmap for the program to be written
→ Increases the reliability, accuracy and efficiency of the desired outcome

5. What are the characteristics of a good algorithm?


→ Clear and Unambiguous: Each step of the algorithm should be clear and easy to understand, with
no confusion about what needs to be done.
→ Uniqueness: The result of each step should be uniquely defined and should only depend on the
input and the results of the preceding steps.
→ Finiteness: The algorithm should have a clear endpoint, meaning it should complete its task in a
finite number of steps.
→ Flexibility: The algorithm should be able to handle a variety of inputs.
→ Correctness: The algorithm should produce correct output for all valid inputs.

6. What are the things that we need to identify before writing an algorithm?
→ Input: Determine what information or data the algorithm needs to start working. This could be
numbers, text, or any other type of data.
→ Process: Understand the steps or operations needed to transform the input into the desired
output.
→ Output: Identify what the expected result or outcome of the algorithm should be.
7. What are the different ways to represent an algorithm?
There are two different ways to represent an algorithm: Pseudocode and Flowchart.

8. What is pseudocode?
The word pseudocode means “not real code”. It is an informal description of an algorithm. It helps in
focusing on the logic without worrying about syntax of any programming language.

9. What are the common keywords used to write pseudocode?


→ START/BEGIN: Indicates the beginning of the pseudocode.
→ END: Marks the end of the pseudocode.
→ INPUT: To take user input.
→ COMPUTE: To make any computation or processing.
→ OUTPUT/PRINT: Used to display information or results.
→ IF...THEN...ELSE: Represents a decision-making process or conditional statement.
→ WHILE: Indicates a loop that continues as long as a condition is true.
→ FOR: Represents a loop that runs a specific number of times.
→ REPEAT...UNTIL: Indicates a loop that continues until a certain condition is met.
→ SET/INITIALIZE: Used to assign a value to a variable.

10. What is flowchart?


A flowchart is a visual diagram that represents the steps of an algorithm using different shapes and
symbols. Each shape represents a different type of action or step, and arrows connect these shapes to
show the flow of control from one step to another.

11. What are the different shapes or symbols used to draw flowchart?
→ Oval (or Ellipse): Used to represent the start and end points of a flowchart.
→ Rectangle: Represents a process or operation where instructions are executed.
→ Diamond: Used for decision-making, where the flow depends on a condition (yes/no or true/false).
→ Parallelogram: Indicates input or output operations, such as entering data or displaying results.
→ Arrow: Shows the direction of flow between steps in the flowchart.
→ Circle: Sometimes used to connect different parts of a flowchart, especially in complex diagrams.

12. What are the different ways on which the control of algorithm flows?
→ Sequential Flow: The algorithm follows steps one after another in a straight line, executing each
step in the order they are written.
→ Selection (Conditional) Flow: The algorithm makes decisions based on conditions. It uses IF...
THEN… ELSE statements to choose different paths depending on whether a condition is true or false.
→ Iteration (Repetition) Flow: The algorithm repeatedly executes a set of instructions as long as a
certain condition is true. This is achieved through loops such as FOR loop or WHILE loop.
13. What do you mean by dry run and how is it helpful?
Dry run is the method of taking an input and running through the steps of the algorithm to check its
correctness. It is helpful to identify if there is any error in the steps and figure out if there are any
missing details.

14. Prepare both pseudocode and flowchart to find square of a number.


Pseudocode:
START
INPUT number
COMPUTE square = number * number
OUTPUT square
END

Draw Flowchart with the hints below:


Start (Oval)
Input number (Parallelogram)
Process: square = number * number (Rectangle)
Output square (Parallelogram)
End (Oval)

15. Prepare both pseudocode and flowchart to add two numbers.


Pseudocode:
START
INPUT number1
INPUT number2
COMPUTE sum = number1 + number2
OUTPUT sum
END

Draw Flowchart with the hints below:


Start (Oval)
Input number1 (Parallelogram)
Input number2 (Parallelogram)
Process: sum = number1 + number2 (Rectangle)
Output sum (Parallelogram)
End (Oval)

16. Prepare both pseudocode and flowchart to find whether a number is odd or even.
Pseudocode:
START
INPUT number
IF number % 2 == 0 THEN
OUTPUT "The number is even"
ELSE
OUTPUT "The number is odd"
END

Draw Flowchart with the hints below:


Start (Oval)
Input number (Parallelogram)
Decision: number % 2 == 0? (Diamond)
Yes:
Output "The number is even" (Parallelogram)
No:
Output "The number is odd" (Parallelogram)
End (Oval)

17. Prepare both pseudocode and flowchart to find the largest among two numbers.
Pseudocode:
START
INPUT num1
INPUT num2
IF num1 >= num2 THEN
SET largest = num1
ELSE
SET largest = num2
OUTPUT largest
END

Draw Flowchart with the hints below:


Start (Oval)
Input num1 (Parallelogram)
Input num2 (Parallelogram)
Decision: num1 >= num2? (Diamond)
Yes:
Process: largest = num1 (Rectangle)
No:
Process: largest = num2 (Rectangle)
Output largest (Parallelogram)
End (Oval)
18. Prepare both pseudocode and flowchart to find sum of first five natural numbers.
Pseudocode:
START
INITIALIZE sum = 0
INITIALIZE i = 1
FOR i <= 5 DO
COMPUTE sum = sum + i
COMPUTE i = i+1
OUTPUT sum
END

Draw Flowchart with the hints below:


Start (Oval)
Initialize sum to 0 (Rectangle)
Initialize i to 1 (Rectangle)
Decision: i <= 5? (Diamond)
Yes:
Process: sum = sum + i (Rectangle)
Process: i = i + 1 (Rectangle)
Loop back to decision (Arrow)
No:
Output sum (Parallelogram)
End (Oval)

19. Prepare both pseudocode and flowchart to find sum any five consecutive numbers.
Pseudocode:
START
INITIALIZE sum = 0
INITIALIZE i = 1
INPUT number
FOR i <= 5 DO
COMPUTE sum = sum + number
COMPUTE number = number+1
COMPUTE i = i+1
OUTPUT sum
END

Draw Flowchart with the hints below:


Start (Oval)
Initialize sum to 0 (Rectangle)
Initialize i to 1 (Rectangle)
Input number (Parallelogram)
Decision: i <= 5? (Diamond)
Yes:
Process: sum = sum + number (Rectangle)
Process: number = number + 1 (Rectangle)
Process: i = i + 1 (Rectangle)
Loop back to decision (Arrow)
No:
Output sum (Parallelogram)
End (Oval)

20. Prepare both pseudocode and flowchart to sum of any five random numbers.

START
INITIALIZE sum = 0
INITIALIZE i = 1
FOR i <= 5 DO
INPUT number
COMPUTE sum = sum + number
COMPUTE i = i+1
OUTPUT sum
END

Draw Flowchart with the hints below:


Start (Oval)
Initialize sum to 0 (Rectangle)
Initialize i to 1 (Rectangle)
Input number (Parallelogram)
Decision: i <= 5? (Diamond)
Yes:
Process: sum = sum + number (Rectangle)
Process: number = number + 1 (Rectangle)
Process: i = i + 1 (Rectangle)
Loop back to decision (Arrow)
No:
Output sum (Parallelogram)
End (Oval)

You might also like