FOR MORE EXAMS
Unit 1
EMAIL:
WGU C960: Supplementary Practice
Module 1: Algorithm Structures With 100%
accurate solutions + rationales
Module 1: Algorithm Structures
Algorithm 1
1: procedure
2: sum = 0
3: for (i=2, i<n, i=i+3) do
4: if i mod 2 == 0
5: sum = sum + i
Solution: sum = 44
With i starting at 2 and incrementing by 3 every iteration, i will iterate
through the values 2, 5, 8, 11, 14, 17, and 20. The if statement means sum will
only be updated when i is even, adding 2, 8, 14, and 20 for a total of 44
2Use the pseudo-code below to answer the following question.
(a) Without working through the pseudo-code, how many times with val be
updated in Line 7?
Solution: 24
The loop in line 5 will iterate 4 times. The loop in line 6 will iterate 6 times.
Since they are nested, we multiply and val will be updated 4 · 6 = 24 times.
Suggestions or errors? Thursday 8th September, 2022
Email the IT Math Team
, C960: Supplementary Practice Unit 1
(b) What is the final value of val.
Solution: val = 210
The algorithm loops through all possible combinations of x and y, multiplies
them, and adds them to val. In the end, we get
1· 1 + 1 · 2 + 1 · 3 + 1 · 4 + 1 · 5 + 1 · 6 +
2· 1 + 2 · 2 + 2 · 3 + 2 · 4 + 2 · 5 + 2 · 6 +
3· 1 + 3 · 2 + 3 · 3 + 3 · 4 + 3 · 5 + 3 · 6 +
4 · 1 + 4 · 2 + 4 · 3 + 4 · 4 + 4 · 5 + 4 · 6 = 210
Algorithm 2
1: procedure
2: dFour = [1, 2, 3, 4]
3: dSix = [1, 2, 3, 4, 5, 6]
4: val = 0
5: for (x in dFour) do
6: for (y in dSix) do
7: val = val + x·y
3 Using the pseudo-code below, what is the ending value for count when n = 100?
When n = 10,000?
When n = 1042?
Algorithm 3
1: procedure
2: count=0
3: while (n>1) do
4: count++
5: n = n/10
Solution:
When n = 100, count will end at 2.
Suggestions or errors? Page 2 of 12 Thursday 8th September, 2022
Email the IT Math Team
Unit 1
EMAIL:
WGU C960: Supplementary Practice
Module 1: Algorithm Structures With 100%
accurate solutions + rationales
Module 1: Algorithm Structures
Algorithm 1
1: procedure
2: sum = 0
3: for (i=2, i<n, i=i+3) do
4: if i mod 2 == 0
5: sum = sum + i
Solution: sum = 44
With i starting at 2 and incrementing by 3 every iteration, i will iterate
through the values 2, 5, 8, 11, 14, 17, and 20. The if statement means sum will
only be updated when i is even, adding 2, 8, 14, and 20 for a total of 44
2Use the pseudo-code below to answer the following question.
(a) Without working through the pseudo-code, how many times with val be
updated in Line 7?
Solution: 24
The loop in line 5 will iterate 4 times. The loop in line 6 will iterate 6 times.
Since they are nested, we multiply and val will be updated 4 · 6 = 24 times.
Suggestions or errors? Thursday 8th September, 2022
Email the IT Math Team
, C960: Supplementary Practice Unit 1
(b) What is the final value of val.
Solution: val = 210
The algorithm loops through all possible combinations of x and y, multiplies
them, and adds them to val. In the end, we get
1· 1 + 1 · 2 + 1 · 3 + 1 · 4 + 1 · 5 + 1 · 6 +
2· 1 + 2 · 2 + 2 · 3 + 2 · 4 + 2 · 5 + 2 · 6 +
3· 1 + 3 · 2 + 3 · 3 + 3 · 4 + 3 · 5 + 3 · 6 +
4 · 1 + 4 · 2 + 4 · 3 + 4 · 4 + 4 · 5 + 4 · 6 = 210
Algorithm 2
1: procedure
2: dFour = [1, 2, 3, 4]
3: dSix = [1, 2, 3, 4, 5, 6]
4: val = 0
5: for (x in dFour) do
6: for (y in dSix) do
7: val = val + x·y
3 Using the pseudo-code below, what is the ending value for count when n = 100?
When n = 10,000?
When n = 1042?
Algorithm 3
1: procedure
2: count=0
3: while (n>1) do
4: count++
5: n = n/10
Solution:
When n = 100, count will end at 2.
Suggestions or errors? Page 2 of 12 Thursday 8th September, 2022
Email the IT Math Team