question archive Consider the following algorithm: sum = 0 for j in range(1,12): sum = sum + (9*j + 7) print(sum) What is printed as a result of executing this algorithm? Your Answer: ----- Consider the following algorithm: g1 = 9 g2 = 2 for k in range(3,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? Your Answer: ------ Q20
Subject:MathPrice:9.82 Bought3
Consider the following algorithm:
sum = 0
for j in range(1,12):
sum = sum + (9*j + 7)
print(sum)
What is printed as a result of executing this algorithm?
Your Answer:
-----
Consider the following algorithm:
g1 = 9
g2 = 2
for k in range(3,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?
Your Answer:
------
Q20. 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, ..., 23}
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?
Your Answer:
-------
Q10A. Consider the following algorithm:
g1 = 4
g2 = 9
for k > 2:
gk = (k-1)·gk-1 - gk-2
What is term g6 of the recursive sequence generated as a result of executing this algorithm?
Your Answer:
------
Q9A. Consider the following algorithm:
sum = 0
for j in range(1,16):
sum = sum + (5*j - 6)
print(sum)
What is printed as a result of executing this algorithm?
Your Answer:
Dear, if you need anything related to question kindly let me know through comments.
The answers are given below-
1)sum = 0
for j in range(1,12):
sum = sum + (9*j + 7)
print(sum)
if we convert this into code-
#include <iostream>
using namespace std;
int main()
{
int j,sum = 0;
for(j=1;j<12;j++){
sum = sum + 9*j + 7;
cout<<sum;
}
}
so the answer is 164175118170231301380468565671
g1 = 9
g2 = 2
for k in range(3,8):
gk = (k-1)·gk-1 + gk-2
if we convert this into code-
#include <iostream>
using namespace std;
int main()
{
int g[8],k;
g[1] = 9,g[2] = 2;
for(k=3;k<=8;k++){
g[k] = (k-1)*g[k-1] + g[k-2];
}
cout<<g[8];
}
so the answer is g[8]=41057
3) 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)
if we convert this into code-
A=range(1,45)
B=range(-7,23)
AminusB=set()
for element in A:
if not element in B:
AminusB, add(element)
n=len(AminusB)
print(n)
so the answer is 22
Step-by-step explanation
10A) g1 = 4
g2 = 9
for k > 2:
gk = (k-1)·gk-1 - gk-2
if we convert this into code-
#include <iostream>
using namespace std;
int main()
{
int g[8],k;
g[1] = 4,g[2] = 9;
for(k=3;k<=8;k++){
g[k] = (k-1)*g[k-1]-g[k-2];
}
cout<<g[6];
}
so the answer of g[6] is 557
9A) sum = 0
for j in range(1,16):
sum = sum + (5*j - 6)
print(sum)
if we convert this into code-
#include <iostream>
using namespace std;
int main()
{
int sum = 0,j;
for(j=1;j<=16;j++){
sum = sum + 5*j - 6;
}
cout<<sum;
}
so the answer is 584