School ICT Self Study

Control Structures in Algorithms

164 viewsG11-01. Programming
0

  1. Name the three main control structures used in algorithm development and give an example of each.

  2. Design an algorithm to find the largest number in a list using iteration and selection.

  3. When would you choose iteration over selection in an algorithm?

  4. Write pseudo code to check if a number is even.

  5. Write pseudo code to print numbers from 1 to 5 using a loop.

Ruwan Suraweera Changed status to publish May 26, 2025
0

Answers and Descriptions

  1. Answer: 1. Sequence: Executing statements in order (e.g., adding two numbers). 2. Selection: Making decisions (e.g., if a number is positive). 3. Iteration: Repeating steps (e.g., printing numbers 1 to 10).
    Description: Control structures guide program flow. Sequence ensures linear execution, selection enables conditional branching, and iteration supports repetition, forming the core of algorithm design.

  2. Answer:

INPUT list
max = list[0]
FOR each number IN list
    IF number > max THEN
        max = number
    ENDIF
ENDFOR
OUTPUT max

Description: This algorithm uses iteration (looping through the list) and selection (comparing numbers) to find the maximum, demonstrating practical application of control structures.

  1. Answer: Use iteration when repeating a task multiple times, such as summing numbers, and selection when making a one-time decision, like checking if a number is positive.
    Description: Choosing the appropriate control structure depends on the problem. Iteration is ideal for repetitive tasks, while selection handles conditional logic, optimizing algorithm efficiency.

  2. Answer:

INPUT number
IF number MOD 2 = 0 THEN
    OUTPUT "Number is even"
ELSE
    OUTPUT "Number is odd"
ENDIF

Description: Pseudo code provides a clear, human-readable algorithm representation. This example uses a selection structure to check divisibility by 2, reinforcing control structure application.

  1. Answer:

FOR i = 1 TO 5
    OUTPUT i
ENDFOR

Description: A for loop is used when the number of iterations is known. This loop prints numbers 1 to 5, illustrating a basic iteration structure for repetitive tasks.

Ruwan Suraweera Changed status to publish May 26, 2025
You are viewing 1 out of 1 answers, click here to view all answers.
Write your answer.