Page 90 - 2502_Pakistan-kifayat_C-6
P. 90
COMBINING SEQUENCE, SELECTION & REPETITION TO SOLVE PROBLEM
In problem-solving and algorithm design, sequence, selection, and repetition are fundamental
constructs that are used to break down and solve complex problems. These three constructs can be
combined in an algorithm to create a structured approach that allows for more flexibility and efficiency
in solving problems.
By combining these three constructs, we can design algorithms that are both powerful and flexible. For
example, when solving a problem that requires decisions to be made repeatedly based on changing
conditions, we can use sequence for the flow of actions, selection for decision-making, and repetition
for performing tasks multiple times.
Example 10: Find the Sum of Odd Numbers from 1 to 50.
Step 1: Start.
Step 2: Set sum=0.
Step 3: Initialise the counter variable 'i' to 1.
Step 4: If counter variable 'i' <=50, go to Step 5; otherwise, go to Step 8.
Step 5: If the remainder when 'i' is divided by 2 is not zero (i.e., i % 2 != 0), go to Step 6; otherwise, go
to Step 7.
Step 6: Add 'i' to 'sum' (i.e., sum = sum + i).
Step 7: Increment 'i' by 1 and go to Step 4.
Step 8: Print the value of 'sum'.
Step 9: Stop.
Timeline
Algorithmic thinking is a skill that involves breaking down a problem into clear, step-by-step
instructions.
Benefits of algorithmic thinking are clear plans, fewer mistakes, speed and efficiency, easy checking
and fixing, better problem-solving skills, and reusable solutions.
An algorithm is a set of precise steps that solve a problem or complete a task.
Sequential statements are instructions that are executed one after another in a specific order.
Conditional (Selection) statements enable decision-making in algorithms.
Iteration (Repetition) statements allow certain instructions to be repeated multiple times until a
condition is met.
Combining Sequence, Selection, and Repetition helps in solving complex problems efficiently.
Choose the correct option.
1. What is the primary benefit of algorithmic thinking?
a. Fewer mistakes b. Better graphics
c. Faster computer processing d. Easier to learn programming
88 Premium Edition-VI

