Overview

"What Does This Program Do?" is an ACSL category that presents a program written in pseudocode and asks you to determine what the program does or what value it outputs. This page focuses specifically on branching (IF-THEN-ELSE statements), which is covered in Junior Division Contest 1.

Key Concepts:

  • Branching: Programs use IF-THEN-ELSE statements to make decisions based on conditions
  • Boolean Expressions: Conditions use comparison operators (>, <, >=, <=, ==, !=) and logical operators (&&, ||, !)
  • Trace Execution: Step through the program line by line, tracking variable values
  • Conditional Logic: Only execute code blocks when their conditions are true

Key Concepts

ACSL Pseudocode - Branching Constructs

ACSL uses a standardized pseudocode format. Here are the key constructs for branching:

Decision Statements (Branching):

IF boolean expression THEN
    Statement(s)
ELSE (optional)
    Statement(s)
END IF

Comparison Operators:

Logical Operators:

How to Solve Branching Problems

Step-by-Step Strategy:

  1. Read the program carefully - Understand what variables are used and their initial values
  2. Identify input values - Note any INPUT statements and what values are provided
  3. Create a tracking table - Make a table with columns for each variable and a row for each step of execution
  4. Trace execution line by line - Follow the program flow, executing statements in order
  5. Evaluate conditions - When you encounter an IF statement, evaluate the boolean expression
  6. Follow the correct branch - Execute the THEN block if true, ELSE block if false (if present)
  7. Update your table - Record variable changes in the table after each operation
  8. Find the output - Determine what value is printed or what the final state is

Common Mistakes to Avoid

Quick Reference

Tips for Success:

  • Always create a tracking table before you start
  • Read the entire program first to understand the flow
  • Work through one IF statement at a time
  • Update your table immediately after each assignment
  • Double-check your condition evaluations
  • Verify your final answer makes logical sense

Examples

Example: What is the output if the input is 15?
INPUT x
y = 0
IF x > 10 THEN
    y = y + 5
END IF
IF x > 20 THEN
    y = y + 10
ELSE
    y = y + 2
END IF
OUTPUT y

Solution using a tracking table:

StepStatementxy
1INPUT x15—
2y = 0150
3y = y + 5 (inside IF x > 10)155
4y = y + 2 (inside ELSE of IF x > 20)157
5OUTPUT y157

Final answer: 7

Practice Problems

Problem 1 Junior

What is printed when this program is run?

x = 10
y = 3
z = 5
w = 2
IF x > z * w THEN
    x = x - z
END IF
IF (y + w) < (x - z) THEN
    y = y + w
ELSE
    z = z + w
END IF
IF x * y == z * w THEN
    x = x * y / w
ELSE
    y = y * z / x
END IF
IF z ↑ 2 >= (w + 1) ↑ 2 THEN
    z = w + 1
ELSE
    w = w + 1
END IF
OUTPUT (x + y) / w + (z + w) ↑ 2

Problem 2 Junior

What is printed when this program is run?

p = 8
q = 4
r = 6
s = 3
IF p > q * s THEN
    p = p - q
END IF
IF (q + s) <= (p - r) THEN
    q = q + s
ELSE
    r = r + s
END IF
IF p * q != r * s THEN
    p = p * q / r
ELSE
    q = q * r / p
END IF
IF r ↑ 2 < (s + 2) ↑ 2 THEN
    r = s + 2
ELSE
    s = s + 2
END IF
IF p + q * r == r + s * q THEN
    p = q * r
ELSE
    r = s * q
END IF
OUTPUT (p + q) / s + (r - s) ↑ 2