You are on page 1of 23

Week-10, Graded Assignment Solution

Week-10, Graded Assignment Solution


Question (1-4)
Statement
Question-1 [5 Marks]
Statement
Options
(a)
(b)
(c)
(d)
Solution
Question (2) [5 Marks]
Statement
Options
(a)
(b)
(c)
(d)
(e)
Solution
Question 3 [5 Marks]
Statement
Options
(a)
(b)
(c)
(d)
(e)
Solution
Question 4 [4 Marks]
Statement
Options
(a)
(b)
(c)
(d)
Solution
Question (5-8)
Statement
Question 5 [5 Marks]
Statement
Options
(a)
(b)
(c)
(d)
Solution
Question (6) [5 Marks]
Statement
Options
(a)
(b)
(c)
(d)
Solution
Question (7) [5 Marks]
Statement
Options
(a)
(b)
(c)
(d)
Solution
Question (8) [5 Marks]
Statement
Options
(a)
(b)
(c)
(d)
Solution
Question (9-10)
Statement
Explanation
Question 9 [5 Marks]
Statement
Options
(a)
(b)
(c)
(d)
Answer
Solution
Question (10) [5 Marks]
Statement
Options
(a)
(b)
(c)
(d)
Answer
Solution

Question (1-4)
Statement
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
8 matrixPh = getAdjMatrix(D, "P")
9 matrixCh = getAdjMatrix(D, "C")
10 matrixMa = getAdjMatrix(D, "M")
11
12 Procedure getAdjMatrix(D, Subject)
13 n = length(keys(D))
14 matrix = createMatrix(n, n)
15 foreach i in rows(matrix){
16 foreach j in columns(matrix){
17 if(i != j){
18 diff = D[i][Subject] - D[j][Subject]
19 if(10 <= diff and diff <= 20){
20 matrix[i][j] = 1
21 }
22 }
23 }
24 }
25 return(matrix)
26 End getAdjMatrix

Question-1 [5 Marks]
Statement
If matrixPh[i][j] = 1, then

Options
(a)

i scored at most 10 and at least 20 more marks in Physics than j

(b)

i scored at least 10 and at most 20 more marks in Physics than j

(c)

j scored at least 10 and at most 20 more marks in Physics than i

(d)

j scored at most 10 and at least 20 more marks in Physics than i

Solution
Consider the procedure getAdjMatrix. For each pair of keys i and j in D, matrix[i] [j] is initialized
with value 0 using the createMatrix procedure. For each pair of values i and j with i 6 = j, D[i]
[Subject] - D[j] [Subject] is stored in diff . If diff is at least 10 and at most 20 then an edge is
added from i to j in the graph by setting the corresponding cell with value 1. Therefore, matrix[i]
[j] is set to 1 if i scored at most 10 and at least 20 more marks than j in the subject which is
passed as the second parameter. matrixPh is constructed based on the Physics marks of the
students. Therefore, i scored at least 10 and at most 20 more marks in Physics than j.

Therefore, the correct option is (b).


Question (2) [5 Marks]
Statement
Choose the correct statement based on above pseudocode.

Options
(a)

For all i, j with i j, matrixPh[i][j] + matrixPh[j][i] = 1

(b)

For all i, j with i j, if matrixPh[i][j] = 1 then matrixPh[j][i] = 0

(c)

For all i, j with i j, if matrixPh[i][j] = 0 then matrixPh[j][i] = 1

(d)

For all i, j with i j, if matrixPh[i][j] = 1 then matrixPh[j][i] = 1

(e)

For all i, j with i j, if matrixPh[i][j] = 0 then matrixPh[j][i] = 0

Solution
Recall the construction of the matrix matrixPh. For each i and j with i j,

i scored at least 10 and at most 20 more marks in Physics than j.

(a) This is False because there can be a pair of students who scored with mark difference at least
21 (Say 90 and 60 marks in Physics) or at most 9 (say same marks in Physics). In this case, both
matrixPh[i][j] = 0 then matrixPh[j][i] = 0.

Therefore, matrixPh[i][j] + matrixPh[j][i] 1.

(b) Suppose matrixPh[j][i] = 1, then

D[j] [“P ”] + 10 ≤ D[i] [“P ”] ≤ D[j] [“P ”] + 20.

That is, D[j] [“P ”] < D[i] [“P ”]. Therefore, There will be no edge from j to i. Thus,

For all i, j with i j, if matrixPh[i][j] = 1 then matrixPh[j][i] = 0

(c) Consider the case that both i and j scored the same marks in Physics. Then, both matrixPh[i]
[j] = 0 and matrixPh[j][i] = 0. This is a counterexample to show that the option is False.

(d) We show that if matrixPh[i][j] = 1 then matrixPh[j][i] = 0. Therefore, this is the negation of the
True statement.

(e) Consider the case that i is scored 10 less than j in Physics. Then, there will be an
edge from j to ibut not from i to j. This is a counterexample for this option.

Therefore, the correct option is (b).


Question 3 [5 Marks]
Statement
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 in 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)

Options
(a)

0 <= matrixHelp[i][j] <= 3

(b)

matrixHelp[i][j] + matrixHelp[j][i] <= 3

(c)

matrixHelp[i][j] matrixHelp[j][i]

(d)

if matrixHelp[i][j] = 0, then matrixHelp[j][i]] = 3

(e)

if matrixHelp[i][j] = 3, then matrixHelp[j][i] = 0

Solution
Observe that the graph represented by the matrix matrix in the procedure getAdjMatrix shows
the help-relationship between the students on a specific subject. For all three subjects Physics,
Chemistry and Mathematics, we created three matrices matrixPh, matrixCh and matrixMa,
respectively. For each i and j, matrixHelp[i][j] is the sum of the corresponding cells in the three
matrices. Therefore, based on the definition of the edges, matrixHelp[i][j] denotes the number of
subjects that i can help j, where the mark difference is bounded between 10 and 20.

(a) Since there are exactly three subject, a student can help the other one in at most three
subjects. Therefore, the following statement is True:

0 <= matrixHelp[i] [j] <= 3


(b) For any subject Subject, either one of them can help to other or none of them can help each
other. Therefore, the following statement is True:

matrixHelp[i] [j] + matrixHelp[j] [i] <= 3

(c) Consider the following case: D[i] = {“P”: 60, “C”: 70, “M”: 80} and D[i] = {“P”: 70, “C”: 60, “M”: 80}. i
can help j in one subject (Physics). Similarly, j can help i in one subject (Chemistry). None of then
can help each other in Mathematics. That is matrixHelp[i] [j] = matrixHelp[i] [j] = 1. Therefore,
the following statement is False:

matrixHelp[i] [j] matrixHelp[j] [i]

(d) Consider the case that both i and j scored the same marks in all three subjects. Then,
matrixHelp[i] [j] = matrixHelp[i] [j] = 0. This is a counterexample for the following statement:

if matrixHelp[i] [j] = 0, then matrixHelp[j] [i] = 3

(e) Suppose i can help j in all three subjects, then i scored at least 10 and at most 20 more marks
than j in all three subjects. That is, j cannot help i in any subject. Therefore, the following
statement is True:

if matrixHelp[i] [j] = 3, then matrixHelp[j] [i] = 0

Therefore, the correct options are (a), (b) and (e).


Question 4 [4 Marks]
Statement
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 }

Options
(a)

1 if(matrixHelp[i][j] > 0 and matrixHelp[j][i] > 0){


2 A = A + 1
3 }
4 if(matrixHelp[i][j] == 3){
5 B = B + 1
6 }

(b)

1 if(matrixHelp[i][j] > 0 and matrixHelp[j][i] > 0){


2 A = A + 1
3 }
4 if(matrixHelp[i][j] > 2){
5 B = B + 1
6 }

(c)

1 if(i < j){


2 if(matrixHelp[i][j] > 0 and matrixHelp[j][i] > 0){
3 A = A + 1
4 }
5 if(matrixHelp[i][j] > 2){
6 B = B + 1
7 }
8 }
(d)

1 if(i < j){


2 if(matrixHelp[i][j] > 0 and matrixHelp[j][i] > 0){
3 A = A + 1
4 }
5 }
6 if(matrixHelp[i][j] > 2){
7 B = B + 1
8 }

Solution
When to update A: if both i and j can help each other in at least one subject, then A shoul be
incremented by one. The following code fragment can do it. Observe

1 if(matrixHelp[i][j] > 0 and matrixHelp[j][i] > 0){


2 A = A + 1
3 }

that the variable A will be incremented twice for each such pair i and j. To avoid the over
counting, we have to consider either i <= j, or j <= i.

When to update B: if both i can help j in all three subject, then B shoul be incremented by one.
The following code fragment can do it. By combining the above code fragments,

1 if(matrixHelp[i][j] == 3){
2 B = B +1
3 }

we get the suitable code as given in option (d) as follows:

1 if(i< j){
2 if(matrixHelp[i][j] > 0 and matrixHelp[j][i] > 0){
3 A = A + 1
4 }
5 }
6 if(matrixHelp[i][j] > 2){
7 B = B + 1
8 }

Therefore, the correct option is (d).


Question (5-8)
Statement
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.

S.No. Authors List

0 [0, 2, 3]

... ...

M-1 [1, 5, 8, n-1]

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.

Question 5 [5 Marks]
Statement
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 }

Options
(a)

1 matrix[j][k] = matrix[j][k] + 1
(b)

1
2 if(j != k){
3 matrix[j][k] = matrix[j][k] + 1
4 }

(c)

1 if(j != k){
2 matrix[j][k] = matrix[j][k] + 1
3 matrix[k][j] = matrix[k][j] + 1
4 }

(d)

1 matrix[j][k] = matrix[j][k] + 1
2 matrix[k][j] = matrix[k][j] + 1

Solution
Our aim is to construct a graph where authors are denoted by vertices and the co-authoring
relationship is denoted by edges. For each book i, books[i] is the list of authors who co-authored
i. For each j and k in books[i], we have add the co-author relationship. Therefore,

1 matrix[j][k] = matrix[j][k] + 1.

Observe that if i and j are the same during the iteration, then we should skip the matrix update.
Therefore, the following code fragment completes the pseudocode:

1 if(j != k){
2 matrix[j][k] = matrix[j][k] + 1
3 }

Therefore, the correct option is (b).


Question (6) [5 Marks]
Statement
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(i != j 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 }

Options
(a)

List of authors who have co-authored a book with both i and j

(b)

List of authors who have co-authored a book with either i or j

(c)

List of authors who have co-authored at least two book with both i and j

(d)

List of authors who have co-authored at least two book with either i or j

Solution
Note that the matrix matrix2 is indexed by pair of authors, and the cells are initialized with an
empty list. Therefore, each edge of the representing graph is labeled with a list. In the three levels
of iteration over books[i], j, k and h are denoting any three authors in the list. The following
condition,
1 j != k and k != h and h != i

captures that the three authors must be a distinct authors. The following condition

1 not(member(matrix2[j][k], h))

captures that the h should not exists in matrix2[j] [k]. Observe that all three authors are co-
authored the book i. Therefore, the matrix2[i] [j] captures the list of authors who have co-
authored a book with both j and k.

Therefore, the correct option is (a).


Question (7) [5 Marks]
Statement
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).

Options
(a)

matrix[i] [j] = 0 and matrix2[i] [j] = [ ]

(b)

matrix[i] [j] = 0 and matrix2[i] [j] []

(c)

matrix[i] [j] > 0 and matrix2[i] [j] = [ ]

(d)

matrix[i] [j] > 0 and matrix2[i] [j] []

Solution
Here we relate matrix and matrix2. The matrix captures the number of books co-authored by a
pair of authors whereas the matrix2 captures the number authors who have co-authored a book
with a pair of authors.

(a) If i and j have not co-authored any book then we will have

1 matrix[i][j] = 0 and matrix2[i][j] = [ ]

(b) If i and j have not co-authored any book then the common third co-authors list will be empty.
On the other hand, if the common third co-authors list is not empty then i and j have co-authored
at least one book. Therefore, the following combination is not possible:

1 matrix[i][j] = 0 and matrix2[i][j] != [ ]

(c) If i and j have co-authored with books where all such books are only co-authored by only i and
j.

1 matrix[i][j] > 0 and matrix2[i][j] = [ ]

(d) If i and j have co-authored with books where some books are co-authored at least
one more author other than i and j.

1 matrix[i][j] > 0 and matrix2[i][j] != [ ]

Therefore, the correct options are (a), (c) and (d).


Question (8) [5 Marks]
Statement
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.

Options
(a)

1 Procedure findAuthor(M)
2 Max = 0
3 A = 0
4 foreach i in rows(M){
5 Sum = 0
6 foreach j in columns(M){
7 if(M[i][j] > 0){
8 Sum = Sum + 1
9 }
10 }
11 if(Sum > Max){
12 Max = Sum
13 A = i
14 }
15 }
16 return(A)
17 End findAuthor

(b)

1 Procedure findAuthor(M)
2 Max = 0
3 A = 0
4 foreach i in rows(M){
5 Sum = 0
6 foreach j in columns(M){
7 if(M[i][j] > 0){
8 Sum = Sum + M[i][j]
9 }
10 }
11 if(Sum > Max){
12 Max = Sum
13 A = i
14 }
15 }
16 return(A)
17 End findAuthor
(c)

1 Procedure findAuthor(M)
2 Max = 0
3 A = 0
4 foreach i in columns(M){
5 Sum = 0
6 foreach j in rows(M){
7 if(M[j][i] > 0){
8 Sum = Sum + 1
9 }
10 }
11 if(Sum > Max){
12 Max = Sum
13 A = i
14 }
15 }
16 return(A)
17 End findAuthor

(d)

1 Procedure findAuthor(M)
2 Max = 0
3 A = 0
4 foreach i in columns(M){
5 Sum = 0
6 foreach j in rows(M){
7 if(M[j][i] > 0){
8 Sum = Sum + M[j][i]
9 }
10 }
11 if(Sum > Max){
12 Max = Sum
13 A = i
14 }
15 }
16 return(A)
17 End findAuthor

Solution
We want to find an author who has the maximum number of co-authors. For any two authors i
and j, matrix[i] [j] stores the number of books co-authored by both i and j. The number of
authors who are co-authored a book with an i can be computed as follows:

1 Sum = 0
2 foreach j in columns(M){
3 if(M[i][j] > 0){
4 Sum = Sum + 1
5 }
6 }
We cans witch the role of i and j since the matrix is symmetric. Based on the pseudocodes in the
options, Max captures the maximum number of co-authors for any author, and A captures such
an author. For each customer i, Sum captures the number of shopping partners of i. Once Sum is
computed for i, we have to check i has more co-authors than the current maximum. By
combining all the above logic, we can obtain the following pseudocode:

1 Procedure findAuthor(M)
2 Max = 0
3 foreach i in rows(M){
4 Sum = 0
5 foreach j in columns(M){
6 if(M[i][j] > 0){
7 Sum = Sum + 1
8 }
9 }
10 if(Sum > Max){
11 Max = Sum
12 A = i
13 }
14 }
15 return(A)
16 End findAuthor

As we mentioned above, the matrix, matrix is a symmetric matrix. That is,

1 matrix[i][j] = matrix[j][i].

Also note that the lists columns(matrix) and rows(matrix) are the same. Therefore, we can
obtain another equivalent pseudocode from the above.

1 Procedure findAuthor(M)
2 Max = 0
3 A = 0
4 foreach i in columns(M){
5 Sum = 0
6 foreach j in rows(M){
7 if(M[i][j] > 0){
8 Sum = Sum + 1
9 }
10 }
11 if(Sum > Max){
12 Max = Sum
13 A = i
14 }
15 }
16 return(A)
17 End findAuthor

Therefore, the correct options are (a) and (c).


Question (9-10)
Statement
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 }

Explanation
As the customers are indexed between 0 to n-1, i and j are the index number of two customers.
From Line 3 and line 4 it is cleared that each and every customer is being compared with each
other customer.

Line 5: i != j means if the customers are not same, then matrix[i][j] = intersection(D[i], D[j]). As D[i]
is the list of shops visited by customer i and D[j] is the list of shops visited by customer j.
intersection(D[i], D[j]) will return the list of the common elements between D[i] and D[j] which
means intersection(D[i], D[j]) returns the list of common shops visited by both the customers i
and j.

Therefore, whenever the different customers let us say i and j, matrix stores the list of common
shops visited by i and j.

Line 8-10: else block will be executed when if block does not get executed. This means when i == j,
matrix[i][j] stores the empty list for the same customer.

Question 9 [5 Marks]
Statement
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

Options
(a)

If there exists three customers who have visited all three shops.

(b)

If there exist three customers such that every pair of customers among them have visited only
one and the same shop in common.

(c)

If there exists three customers who have visited exactly one shop.

(d)

If there exists three customers where each pair among them have visited exactly one shop in
common.

Answer
(b)

Solution
Fix some values for i, j, and h from 0 to n-1.

Line 5: list1 is initialized with an empty list.

Line 6: There are two condition added by "and". Therefore to get executed this if block, both the
conditions should be True. The first condition is

1 length(M[i][j]) == 1
As M[i][j] stores the list of shops visited by both the customers and if the length is 1, then
customers i and j have visited only one common shop.

The second condition is given as

1 member(D[h], first(M[i][j]))

As D[h] is the list of shops visited by the customer h, and first(M[i][j]) is the first element of list
store by M in i, j cell. M[i][j] is the list of shops visited by both i and j and from previous condition if
the length is 1 then M[i][j] contains only one shop if it is in D[h] then i, j have visited only one
common shop (pair-wise) and that shop is also visited by h.

Line 7: The common shop will be appended in list1.

Line 9 - 11: list1 will append the a shop, if this shop is the only one common shop visited by i and
h, and it is also visited by j.

Line 12 - 14: list1 will append the a shop, if this shop is the only one common shop visited by j and
h, and it is also visited by i.

Line 15: All the duplicates will be removed from list1.

If length(list1) == 1, then i, j, and h have visited only one common shop pairwise and only one
shop common overall too.

The correct option is (b).


Question (10) [5 Marks]
Statement
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.

Options
(a)

1 Procedure findTopCustomer(M)
2 Max = 0, A = 0
3 foreach i in rows(M){
4 C = 0
5 foreach j in columns(M) {
6 if(length(M[i][j]) == 2){
7 C = C + 1
8 }
9 }
10 if(C > Max){
11 Max = C
12 A = i
13 }
14 }
15 return(A)
16 End findTopCustomer

(b)

1 Procedure findTopCustomer(M)
2 Max = 0, A = 0
3 foreach i in rows(M){
4 C = 0
5 foreach j in columns(M){
6 if(length(M[i][j]) > 1){
7 C = C + 1
8 }
9 }
10 if(C > Max){
11 Max = C
12 A = i
13 }
14 }
15 return(A)
16 End findTopCustomer
(c)

1 Procedure findTopCustomer(M)
2 Max = 0, A = 0
3 foreach i in rows(M){
4 C = 0
5 foreach j in columns(M) {
6 if(length(M[i][j]) == 2){
7 C = C + 1
8 }
9 }
10 if(C > Max){
11 Max = C
12 A = i
13 }
14 }
15 return(Max)
16 End findTopCustomer

(d)

1 Procedure findTopCustomer(M)
2 Max = 0, A = 0
3 foreach i in rows(M){
4 C = 0
5 foreach j in columns(M){
6 if(length(M[i][j]) > 1){
7 C = C + 1
8 }
9 }
10 if(C > Max){
11 Max = C
12 A = i
13 }
14 }
15 return(Max)
16 End findTopCustomer

Answer
(b)

Solution
We want to find the customer who have the maximum shopping partner. As per definition of the
shopping partner, i and j should have visited at least two common shops. This can be captured
using the following conditional statement:

length(M[i] [j]) >= 2 or length(M[i] [j]) > 1


Based on the pseudocodes in the options, Max captures the maximum number of shopping
partners for any customer, and A captures the customer who has maximum shopping partner.
for each customer i, C captures the number of shopping partners of i. Once C is computed for i,
we have to check i has more partner than the current maximum. By combining all the above logic,
we can obtain the following pseudocode:

1 Procedure findTopCustomer(M)
2 Max = 0, A = 0
3 foreach i in rows(M){
4 C = 0
5 foreach j in columns(M){
6 if(length(M[i][j] > 1)){
7 C = C + 1
8 }
9 }
10 if(C > Max){
11 Max = C
12 A = i
13 }
14 }
15 return(A)
16 End findTopCustomer

The correct option is (b).

You might also like