School ICT Self Study

Algorithm Representation Tools

153 viewsG11-01. Programming
0

Algorithm Representation Tools

  1. What does an oval symbol represent in a flowchart?

  2. Convert the following pseudo code into a flowchart:

INPUT age
IF age >= 18 THEN
    OUTPUT "Eligible to vote"
ELSE
    OUTPUT "Not eligible"
ENDIF
  1. Optimize the following pseudo code to check if a number is prime:

INPUT n
isPrime = TRUE
FOR i = 2 TO n-1
    IF n MOD i = 0 THEN
        isPrime = FALSE
    ENDIF
ENDFOR
  1. Write pseudo code to assign a grade based on a score (90-100: A, 80-89: B, below 80: C).

  2. When is a switch/case statement preferred over If-Else?

Ruwan Suraweera Changed status to publish May 26, 2025
0

Answers and Descriptions

  1. Answer: An oval symbol represents the start or end of a flowchart.
    Description: Flowcharts use standardized symbols to visualize algorithms. The oval marks the entry or exit point, clearly defining the algorithm’s boundaries.

  2. Answer: Start (Oval) β†’ Input age (Parallelogram) β†’ Decision (Diamond: age >= 18?) β†’ Yes: Output β€œEligible to vote” (Rectangle) β†’ No: Output β€œNot eligible” (Rectangle) β†’ End (Oval).
    Description: Converting pseudo code to a flowchart reinforces understanding of both tools. The flowchart visually represents the decision-making process for voting eligibility.

  3. Answer:

INPUT n
isPrime = TRUE
FOR i = 2 TO SQRT(n)
    IF n MOD i = 0 THEN
        isPrime = FALSE
        BREAK
    ENDIF
ENDFOR

Description: Optimizing pseudo code reduces iterations. Checking up to the square root of n and breaking when a divisor is found improves efficiency for prime number checks.

  1. Answer:

INPUT score
IF score >= 90 THEN
    grade = 'A'
ELSE IF score >= 80 THEN
    grade = 'B'
ELSE
    grade = 'C'
ENDIF
OUTPUT grade

Description: The If-Else-EndIf structure evaluates conditions to assign grades, demonstrating selection control structures for multi-condition logic.

  1. Answer: Switch/case is preferred when a single variable is tested against multiple fixed values.
    Description: Switch/case simplifies code for checking a variable (e.g., day of the week) against constants, improving readability over multiple If-Else statements.

Ruwan Suraweera Changed status to publish May 26, 2025
Write your answer.