Introduction To Problem Solving - CLass Notes
Introduction To Problem Solving - CLass Notes
3. What is algorithm?
An algorithm is a sequence of a finite number of unique steps to accomplish a task or solve a
problem.
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.
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.
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
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
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
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