WGU C960 Discrete Mathematics II:
The Ultimate Q&A Study Guide — 180
Essential Problems with Detailed
Explanations
Algorithms and Algorithm Analysis
What are the three building blocks of algorithms?
Assignments, conditional statements, and loops. Assignments give values to
variables, conditional statements control the flow of steps, and loops allow
steps to be repeated.
What is an algorithm?
A step-by-step procedure for solving a problem. It usually specifies the
input and output to a problem, and the sequence of steps to be followed to
obtain the output from the input.
What is pseudocode?
A detailed yet readable description of what an algorithm must do,
expressed in a formally-styled natural language rather than in a
programming language.
What is an IF statement?
,Tests a condition and executes one or more instructions if the condition
evaluates to true.
What is an IF-ELSE statement?
Tests a condition, executes one or more instructions if the condition
evaluates to true, and executes a different set of instructions if the
condition evaluates to false.
What is an iteration?
A process where a set of instructions or structures are repeated in a
sequence a specified number of times or until a condition is met.
What is a For loop?
A block of instructions is executed a fixed number of times as specified in
the first line of the for-loop, which defines an index, a starting value, and a
final value.
What is a While loop?
A while loop iterates an unknown number of times, ending when a certain
condition becomes false.
What is a nested loop?
When a loop exists within another loop.
What is the final value of abs after the following pseudocode is run? x
:= 2 If (x > 0) abs := x Else abs := -x End-if
The final value is 2. The condition (x > 0) evaluates to true because x = 2.
The line abs := x is executed, assigning the value 2 to abs. The Else branch
is skipped entirely.
, What is the final value of abs after the following pseudocode is run? x
:= -2 If (x > 0) abs := x Else abs := -x End-if
The final value is 2. The condition (x > 0) evaluates to false because x = -2.
The Else branch executes, setting abs := -x = -(-2) = 2.
What is the final value of product after the following pseudocode
runs? product := 1 count := 5 While (count > 0) product := product *
count count := count - 2 End-while
The final value is 15. First iteration: count = 5, product = 1 × 5 = 5, count
becomes 3. Second iteration: count = 3, product = 5 × 3 = 15, count
becomes 1. The loop will execute a third iteration (count = 1).
How many iterations will a loop execute if count starts at 5 and
decreases by 2 each iteration while count > 0?
Three iterations. Count values: 5, 3, 1. Each time count > 0, the loop
executes. When count becomes -1, the condition is false.
What are the primary resources to optimize in an algorithm?
Time complexity (the time the algorithm requires to run) and space
complexity (the amount of memory used).
What factors does time complexity depend on?
The speed of the processing unit, the number of calculations that need to
be performed, the number of conditions that need to be evaluated, and the
number of iterations to be completed by the loops.
What are atomic operations?
The Ultimate Q&A Study Guide — 180
Essential Problems with Detailed
Explanations
Algorithms and Algorithm Analysis
What are the three building blocks of algorithms?
Assignments, conditional statements, and loops. Assignments give values to
variables, conditional statements control the flow of steps, and loops allow
steps to be repeated.
What is an algorithm?
A step-by-step procedure for solving a problem. It usually specifies the
input and output to a problem, and the sequence of steps to be followed to
obtain the output from the input.
What is pseudocode?
A detailed yet readable description of what an algorithm must do,
expressed in a formally-styled natural language rather than in a
programming language.
What is an IF statement?
,Tests a condition and executes one or more instructions if the condition
evaluates to true.
What is an IF-ELSE statement?
Tests a condition, executes one or more instructions if the condition
evaluates to true, and executes a different set of instructions if the
condition evaluates to false.
What is an iteration?
A process where a set of instructions or structures are repeated in a
sequence a specified number of times or until a condition is met.
What is a For loop?
A block of instructions is executed a fixed number of times as specified in
the first line of the for-loop, which defines an index, a starting value, and a
final value.
What is a While loop?
A while loop iterates an unknown number of times, ending when a certain
condition becomes false.
What is a nested loop?
When a loop exists within another loop.
What is the final value of abs after the following pseudocode is run? x
:= 2 If (x > 0) abs := x Else abs := -x End-if
The final value is 2. The condition (x > 0) evaluates to true because x = 2.
The line abs := x is executed, assigning the value 2 to abs. The Else branch
is skipped entirely.
, What is the final value of abs after the following pseudocode is run? x
:= -2 If (x > 0) abs := x Else abs := -x End-if
The final value is 2. The condition (x > 0) evaluates to false because x = -2.
The Else branch executes, setting abs := -x = -(-2) = 2.
What is the final value of product after the following pseudocode
runs? product := 1 count := 5 While (count > 0) product := product *
count count := count - 2 End-while
The final value is 15. First iteration: count = 5, product = 1 × 5 = 5, count
becomes 3. Second iteration: count = 3, product = 5 × 3 = 15, count
becomes 1. The loop will execute a third iteration (count = 1).
How many iterations will a loop execute if count starts at 5 and
decreases by 2 each iteration while count > 0?
Three iterations. Count values: 5, 3, 1. Each time count > 0, the loop
executes. When count becomes -1, the condition is false.
What are the primary resources to optimize in an algorithm?
Time complexity (the time the algorithm requires to run) and space
complexity (the amount of memory used).
What factors does time complexity depend on?
The speed of the processing unit, the number of calculations that need to
be performed, the number of conditions that need to be evaluated, and the
number of iterations to be completed by the loops.
What are atomic operations?