Computational Thinking week 10 graded assignment Complete Solutions Are Discussed In This Blog. We Hope This Might Help You All In Matching Answers . Or For Some Others Reasons If Not Able To Complete Graded Assignments
1.The following pseudocode is executing using the “Scores” table. At the end of the execution, matrix represents the adjacency matrix of the graph generated from the “Scores” table.
1
D = {}
2
while(Table 1 has more rows){
3
Read the first row X in Table 1
4
D[X.SeqNo] = {"P": X.Physics, "C": X.Chemistry, "M": X.Mathematics}
5
Move X to Table 2
6
}
7
matrixPh = getAdjMatrix(D, "P")
8
matrixCh = getAdjMatrix(D, "C")
9
matrixMa = getAdjMatrix(D, "M")
10
11
Procedure getAdjMatrix(D, Subject)
12
n = length(keys(D))
13
matrix = createMatrix(n, n)
14
foreach i in rows(matrix){
15
foreach j in columns(matrix){
16
if(i != j){
17
diff = D[i][Subject] - D[j][Subject]
18
if(10 <= diff and diff <= 20){
19
matrix[i][j] = 1
20
}
21
}
22
}
23
}
24
return(matrix)
25
End getAdjMatrix
If matrixPh[i] [j] = 1, then
i scored at most 10 and at least 20 more marks in Physics than j
i scored at least 10 and at most 20 more marks in Physics than j
j scored at least 10 and at most 20 more marks in Physics than i
j scored at most 10 and at least 20 more marks in Physics than i
For all i, j with i
≠= j, matrixPh[i][j] + matrixPh[j][i] = 1
For all i, j with i
≠= j, if matrixPh[i][j] = 1 then matrixPh[j][i] = 0
For all i, j with i
≠= j, if matrixPh[i][j] = 0 then matrixPh[j][i] = 1
For all i, j with i
≠= j, if matrixPh[i][j] = 1 then matrixPh[j][i] = 1
For all i, j with i
≠= j, if matrixPh[i][j] = 0 then matrixPh[j][i] = 0
3.Consider the dictionary D, and the matrices matrixPh, matrixCh and matrixMa computed in the previous question. The following pseudocode generate the adjacency matrix matrixHelp.
1
n = length(keys(D))
2
matrixHelp = createMatrix(n, n)
3
foreach i in rows(matrixHelp){
4
foreach j in columns(matrixHelp){
5
matrixHelp[i][j] = matrixCh[i][j] + matrixPh[i][j] + matrixMa[i][j]
6
}
7
}
Let i and j be indices of two students. Choose the correct statement(s) from the given options. It is a Multiple Select Question (MSQ)
0 <= matrixHelp[i][j] <= 3
matrixHelp[i][j] + matrixHelp[j][i] <= 3
matrixHelp[i][j]
≠= matrixHelp[j][i]
if matrixHelp[i][j] = 0, then matrixHelp[j][i] = 3
if matrixHelp[i][j] = 3, then matrixHelp[j][i] = 0
4.At the end of the following pseudocode, A captures the number of distinct pairs of students who can help each other in at least one subject, and B captures the number of distinct pairs of students where one can help the other in all subjects. Choose the correct code fragment to complete the pseudocode.
1
A = 0, B = 0
2
foreach i in rows(matrixHelp){
3
foreach j in columns(matrixHelp){
4
***********************
5
*** Fill the code ***
6
***********************
7
}
8
}
9
if(matrixHelp[i][j] > 0 and matrixHelp[j][i] > 0){
A = A + 1
}
if(matrixHelp[i][j] == 3){
B = B + 1
}
if(matrixHelp[i][j] > 0 and matrixHelp[j][i] > 0){
A = A + 1
}
if(matrixHelp[i][j] > 2){
B = B + 1
}
if(i < j){
if(matrixHelp[i][j] > 0 and matrixHelp[j][i] > 0){
A = A + 1
}
if(matrixHelp[i][j] > 2){
B = B + 1
}
}
if(i < j){
if(matrixHelp[i][j] > 0 and matrixHelp[j][i] > 0){
A = A + 1
}
}
if(matrixHelp[i][j] > 2){
B = B + 1
}
Question (5-8)
The following table contains information regarding books in a library. Each entry in the table corresponds to a book and is authored by at least two authors. There is a pool of n authors, each author being assigned a unique index between 0 and n − 1. There are M books in total.
The table is represented by a dictionary named books, with the keys as serial numbers and values as the corresponding list of authors. Assume that books has already been computed. For example, we have: books[0] = [0, 2, 3]. Consider the followig question.
4.The following pseudocode generates a graph G from books. Each node corresponds to an author. There is an edge between two different authors i and j if they have co-authored a book, and the edge is labeled with the number of books they have co-authored. Choose the correct code fragment to complete the following pseudocode.
1
matrix = createMatrix(n, n)
2
foreach i in keys(books){
3
foreach j in books[i]{
4
foreach k in books[i]{
5
***********************
6
*** Fill the code ***
7
***********************
8
}
9
}
10
}
matrix[j][k] = matrix[j][k] + 1
if(j != k){
matrix[j][k] = matrix[j][k] + 1
}
if(j != k){
matrix[j][k] = matrix[j][k] + 1
matrix[k][j] = matrix[k][j] + 1
}
matrix[j][k] = matrix[j][k] + 1
matrix[k][j] = matrix[k][j] + 1
5.The following pseudocode creates adjacency matrix matrix2 of another graph H from books. For two different authors i and j, what does the value matrix2[i][j] represent at the end of the execution?
1
matrix2 = createMatrix(n, n)
2
foreach j in rows(matrix2){
3
foreach k in columns(matrix2){
4
matrix2[j][k] = []
5
}
6
}
7
foreach i in keys(books){
8
foreach j in book[i]{
9
foreach k in books[i]{
10
foreach h in books[i]{
11
if(j != k and j != h and k != h and not member(matrix2[j][k], h)){
12
matrix2[j][k] = matrix2[j][k] ++ [h]
13
matrix2[k][j] = matrix2[k][j] ++ [h]
14
}
15
}
16
}
17
}
18
}
List of authors who have co-authored a book with both i and j
List of authors who have co-authored a book with either i or j
List of authors who have co-authored at least two book with both i and j
List of authors who have co-authored at least two book with either i or j
6.Which of the following combinations of entries in matrix and matrix2 is possible for two different authors i and j? It is Multiple Select Question (MSQ).
matrix[i] [j] = 0 and matrix2[i] [j] = [ ]
matrix[i][j] = 0 and matrix2[i][j]
≠= [ ]
matrix[i][j] > 0 and matrix2[i][j] = [ ]
matrix[i][j] > 0 and matrix2[i][j]
≠= [ ]
Consider the matrices matrix and matrix2 constructed in the previous questions.
findAuthor(matrix) finds an author who has the maximum number of co-authors. Choose the correct implementation of the procedure findAuthor. It is a Multiple Select Question.
Procedure findAuthor(M)
Max = 0
A = 0
foreach i in rows(M){
Sum = 0
foreach j in columns(M){
if(M[i][j] > 0){
Sum = Sum + 1
}
}
if(Sum > Max){
Max = Sum
A = i
}
}
return(A)
End findAuthor
Procedure findAuthor(M)
Max = 0
A = 0
foreach i in rows(M){
Sum = 0
foreach j in columns(M){
if(M[i][j] > 0){
Sum = Sum + M[i][j]
}
}
if(Sum > Max){
Max = Sum
A = i
}
}
return(A)
End findAuthor
Procedure findAuthor(M)
Max = 0
A = 0
foreach i in columns(M){
Sum = 0
foreach j in rows(M){
if(M[j][i] > 0){
Sum = Sum + 1
}
}
if(Sum > Max){
Max = Sum
A = i
}
}
return(A)
End findAuthor
Procedure findAuthor(M)
Max = 0
A = 0
foreach i in columns(M){
Sum = 0
foreach j in rows(M){
if(M[j][i] > 0){
Sum = Sum + M[j][i]
}
}
if(Sum > Max){
Max = Sum
A = i
}
}
return(A)
End findAuthor
Question (9-10)
The following pseudocode is executing using the “Shopping bills” dataset. Each customer is being assigned a unique index between 0 and n − 1. Dictionary D has already been computed with keys as index and values as list of distinct shops visited by the corresponding customer. Assume that there exists a procedure intersection which takes two lists as input and outputs another list which contains the common elements in the input lists.
1
n = length(keys(D))
2
matrix = createMatrix(n, n)
3
foreach i in rows(matrix){
4
foreach j in columns(matrix){
5
if(i != j){
6
matrix[i][j] = intersection(D[i], D[j])
7
}
8
else{
9
matrix[i][j] = []
10
}
11
}
12
}
Consider the adjacency matrix matrix constructed above. Assume that there exists a procedure removeDuplicate which receives a list as input and removes all duplicate elements in the list. When will findGoodSet(matrix) return True?
1
Procedure findGoodSet(M)
2
foreach i in rows(M){
3
foreach j in columns(M){
4
foreach h in rows(M){
5
list1 = []
6
if(length(M[i][j]) == 1 and member(D[h], first(M[i][j]))){
7
list1 = list1 ++ M[i][j]
8
}
9
if(length(M[i][h]) == 1 and member(D[j], first(M[i][h]))){
10
list1 = list1 ++ M[i][h]
11
}
12
if(length(M[j][h]) == 1 and member(D[i], first(M[j][h]))){
13
list1 = list1 ++ M[j][h]
14
}
15
list1 = removeDuplicate(list1)
16
if(length(list1) == 1){
17
return(True)
18
}
19
}
20
}
21
}
22
return(False)
23
End findGoodSet
If there exists three customers who have visited all three shops.
If there exist three customers such that every pair of customers among them have visited only one and the same shop in common.
If there exists three customers who have visited exactly one shop.
If there exists three customers where each pair among them have visited exactly one shop in common.
10.For a pair of customers i and j, j is said to be shopping partner of i if i and j have visited at least two shops in common. findTopCustomer(matrix) finds a customer who has the maximum shopping partners. Choose the correct implementation of findTopCustomer.
Procedure findTopCustomer(M)
Max = 0, A = 0
foreach i in rows(M){
C = 0
foreach j in columns(M) {
if(length(M[i][j]) == 2){
C = C + 1
}
}
if(C > Max){
Max = C
A = i
}
}
return(A)
End findTopCustomer
Procedure findTopCustomer(M)
Max = 0, A = 0
foreach i in rows(M){
C = 0
foreach j in columns(M){
if(length(M[i][j]) > 1){
C = C + 1
}
}
if(C > Max){
Max = C
A = i
}
}
return(A)
End findTopCustomer
Procedure findTopCustomer(M)
Max = 0, A = 0
foreach i in rows(M){
C = 0
foreach j in columns(M) {
if(length(M[i][j]) == 2){
C = C + 1
}
}
if(C > Max){
Max = C
A = i
}
}
return(Max)
End findTopCustomer
Procedure findTopCustomer(M)
Max = 0, A = 0
foreach i in rows(M){
C = 0
foreach j in columns(M){
if(length(M[i][j]) > 1){
C = C + 1
}
}
if(C > Max){
Max = C
A = i
}
}
return(Max)
End findTopCustomer
All answers are correct 👍.
Thanks for the great efforts 🔥.
Dii maths ka kab ayega?
Updated On Youtube Full Solution Due To High Demand