Question
Question 1 Consider the following algorithm: sum = 0 For j starting at 1 and ending with 13: sum = sum + (8*j + 4)
Question 1
Consider the following algorithm:
sum = 0
For j starting at 1 and ending with 13: sum = sum + (8*j + 4) print(sum)
What is printed as a result of executing this algorithm?
Question 2
Consider the following algorithm:
g1 = 5
g2 = 9
For k starting at 3 and ending with 8:
gk = (k-1)gk-1 + gk-2
What is the last term, g8, of the recursive sequence generated as a result of executing this algorithm?
Question 3
Suppose a computer program has been initialized such that the following sets have been stored for use in any algorithm:
A = {1, 2, 3, ..., 49} B = {-7, -6, -5, ..., 28}
Consider the following algorithm, which represents one part of the whole computer program (comments may occur after the # symbol on any line and are not used in computations):
#Part 1: computes A - B and its cardinality
AminusB = set() for element in A: # this line runs through every element in A if not(element in B): #A - B is the set of elements that are in A and are not in B AminusB.add(element) # Add to AminusB every element in A if the element is also not in B
n = len(AminusB) #len() returns the number of elements in the array print(n)
What value is printed as a result of executing this algorithm?
Question 4
Consider the following algorithm:
g1 = 7
g2 = 4
for k > 2:
gk = (k-1)gk-1 - gk-2
What is term g6of the recursive sequence generated as a result of executing this algorithm?
Question 5
Consider the following algorithm:
sum = 0
for j in range(1,16): sum = sum + (8*j - 3) print(sum)
What is printed as a result of executing this algorithm?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started