School ICT Self Study

Control Structures in Algorithms

44 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.

Spread the love
Ruwan Suraweera Changed status to publish 4 days ago
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:

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:

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:

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.

Spread the love
Ruwan Suraweera Changed status to publish 4 days ago
Write your answer.