End Term Mock Sep22 Unanswered

Download as pdf or txt
Download as pdf or txt
You are on page 1of 37

End Term Mock

Question 1 [3 Marks]
Statement
The following pseudocode is executed using the "Shopping Bills" dataset. At the end of the
execution, A captures the highest "Price" of an item purchased from "Big Bazaar". Choose the
correct code fragment to complete the pseudocode.

1 A = 0
2 while(Pile 1 has more cards){
3 Read the top card X in Pile 1
4 if(X.ShopName == "Big Bazaar"){
5 temp = findItem(X)
6 if(temp > A){
7 A = temp
8 }
9 }
10 Move X to Pile 2
11 }
12
13 Procedure findItem(Y)
14 maxPrice = 0
15 while(Y.ItemList has more rows){
16 *********************
17 * Fill the code *
18 *********************
19 }
20 return(maxPrice)
21 End findItem

Options
(a)

1 Read first item Z from ItemList of card Y


2 if(Z.Price >= maxPrice){
3 maxPrice = Z.Price
4 }
5 Remove Z from ItemList of card Y

(b)
1 Read first item Z from ItemList of card Y
2 if(maxPrice >= Z.Price){
3 maxPrice = Z.Price
4 }
5 Remove Z from ItemList of card Y

(c)

1 Read first item Z from ItemList of card Y


2 if(maxPrice >= Z.Price){
3 maxPrice = Z.Price
4 }

(d)

1 Read first item Z from ItemList of card Y


2 if(maxPrice >= Z.Price){
3 maxPrice = Z.Price
4 }

Answer
Question 2 [3 Marks]
Statement
The following pseudocode is executed using the “Library” dataset. What will B represent at the
end of the execution?

1 A = 0, B = 0
2 while(Table 1 has more rows){
3 Read the first row X in Table 1
4 if(X.Language == "English"){
5 A = A + 1
6 }
7 else{
8 if(X.Language == "English" or X.Genre == "Fiction"){
9 B = B + 1
10 }
11 }
12 Move X to Table 2
13 }

Options
(a)

Number of fictional books

(b)

Number of fictional books written in other than English

(c)

Number of books written in English + Number of fictional books

(d)

Number of books written in English + Number of fictional books written in other than English

(e)

Number of fictional books + Number of non-fictional books written in English

Answer
Question 3 [4 Marks]
Statement
The following pseudocode is executed using the "Scores" table. At the end of the execution, A
captures the number of pairs of students who have scored the same marks in all subjects. Choose
the correct code fragment to complete the pseudocode.

1 A = 0
2 while(Table 1 has more rows){
3 Read the first row X in Table 1
4 Move X to Table 2
5 while(Table 1 has more rows){
6 Read the first row Y in Table 1
7 Move Y to Table 3
8 *********************
9 * Fill the code *
10 *********************
11 }
12 Move all rows from Table 3 to Table 1
13 }

Options
(a)

1 B = False
2 if(X.Chemistry == Y.Chemistry){
3 B = True
4 }
5 if(X.Mathematics == Y.Mathematics){
6 B = True
7 }
8 if(X.Physics == Y.Physics){
9 B = True
10 }
11 if(not(B)){
12 A = A + 1
13 }

(b)
1 B = True
2 if(X.Chemistry != Y.Chemistry){
3 B = False
4 }
5 if(X.Mathematics != Y.Mathematics){
6 B = False
7 }
8 if(X.Physics != Y.Physics){
9 B = False
10 }
11 if(B){
12 A = A + 1
13 }

(c)

1 B = 0
2 if(X.Chemistry == Y.Chemistry){
3 B = B + 1
4 }
5 if(X.Mathematics == Y.Mathematics){
6 B = B + 1
7 }
8 if(X.Physics == Y.Physics){
9 B = B + 1
10 }
11 if(B > 1){
12 A = A + 1
13 }

(d)

1 B = 0
2 if(X.Chemistry == Y.Chemistry){
3 B = B + 1
4 }
5 if(X.Mathematics == Y.Mathematics){
6 B = B + 1
7 }
8 if(X.Physics == Y.Physics){
9 B = B + 1
10 }
11 if(B == 1){
12 A = A + 1
13 }

Answer
Question - 4 [5 Marks]
Statement
getSpecial is a procedure that accepts a non empty list of distinct integers L as parameter and
returns a pair of two integers. The first element of the pair is the minimum element in L and the
second element of the pair is the maximum element in L. Choose the correct code fragment to
complete the procedure.

1 Procedure getSpecial(L)
2 min = first(L), max = Last(L)
3 if(first(L) > last(L)){
4 min = last(L)
5 max = first(L)
6 }
7
8 if(length(L) == 2){
9 return([min, max])
10 }
11
12 L = init(rest(L))
13 if(first(L) < min){
14 min = first(L)
15 }
16 if(first(L) > max{
17 max = first(L)
18 }
19 ** Fill the code **
20 End getSpecial

Options
(a)

1 return(getSpecial([min] ++ rest(L) ++ [max]))

(b)

1 return(getSpecial([min] ++ init(L) ++ [max]))

(c)

1 return(getSpecial([min] ++ int(rest(L)) ++ [max]))

(d)

1 return(getSpecial([min] ++ first(L) ++ [max]))


Answer
Question 5 [5 Marks]
Statement
Let X and Y be two rows in the “Library” table. We call X and Y compatible if books in rows X and Y
are either published in the same year or under the same genre but not both. Let Compatible(X,
Y) be a procedure to find whether X and Y are compatible. Choose the correct implementation of
the procedure Compatible.

Options
(a)

1 Procedure Compatible(X, Y)
2 A = False, B = False
3 if(X.Year == Y.Year){
4 A = True
5 }
6 if(X.Genre == Y.Genre){
7 B = True
8 }
9 if(A and B){
10 return(True)
11 }
12 return(False)
13 End Compatible

(b)

1 Procedure Compatible(X, Y)
2 A = False, B = False
3 if(X.Year == Y.Year){
4 A = True
5 }
6 if(X.Genre == Y.Genre){
7 B = True
8 }
9 if(A or B){
10 return(True)
11 }
12 return(False)
13 End Compatible

(c)
1 Procedure Compatible(X, Y)
2 A = False, B = False
3 if(X.Year == Y.Year){
4 A = True
5 }
6 if(X.Genre == Y.Genre){
7 B = True
8 }
9 if((A and B == False) or (A or B)){
10 return(True)
11 }
12 return(False)
13 End Compatible

(d)

1 Procedure Compatible(X, Y)
2 A = False, B = False
3 if(X.Year == Y.Year){
4 A = True
5 }
6 if(X.Genre == Y.Genre){
7 B = True
8 }
9 if((A and B == False) and (A or B)){
10 return(True)
11 }
12 return(False)
13 End Compatible

Answer
Question 6 [5 Marks]
Statement
The following pseudocode is executed using the “Scores” dataset. What does L store at the end of
the execution?

1 D = {}
2 L = []
3 while(Table 1 has more rows){
4 Read the first row X in Table 1
5 if(isKey(D, X.TownCity)){
6 if(not member(D[X.TownCity], X.Gender)){
7 D[X.TownCity] = D[X.TownCity] ++ [X.Gender]
8 }
9 }
10 else{
11 D[X.TownCity] = [X.Gender]
12 }
13 Move X to Table 2
14 }
15 foreach i in keys(D){
16 if(length(D[i]) > 1){
17 L = L ++ [i]
18 }
19 }

Options
(a)

List of cities that have more than one student

(b)

List of cities that have at least one boy and at least one girl

(c)

List of cities that have either boys or girls, but not both

(d)

List of cities that have exactly one boy or exactly one girl

Answer
Question 7 [4 Marks]
Statement
The following pseudocode is executed using the “Scores” dataset. What will first(D[i]) - last(D[i])
represent for a given key i ?

1 D = {}
2 while(Table 1 has more rows){
3 Read the first row X in Table 1
4 if(isKey(D, X.TownCity)){
5 if(first(D[X.TownCity]) < X.Mathematics){
6 D[X.TownCity] = [X.Mathematics, last(D[X.TownCity])]
7 }
8 if(last(D[X.TownCity]) > X.Mathematics){
9 D[X.TownCity] = [first(D[X.TownCity]), X.Mathematics]
10 }
11 }
12 else{
13 D[X.TownCity] = [X.Mathematics, X.Mathematics]
14 }
15 Move X to Table 2
16 }

Options
(a)

The difference between highest and lowest Mathematics marks of the city i

(b)

The difference between overall highest and lowest Mathematics marks of the dataset

(c)

The difference between highest and second highset Mathematics marks of the city i

(d)

It will be always 0.

Answer
Question (8 - 9)
Statement
The following pseudocode is executed using the “Shopping Bills” dataset.

1 itemD = {}, costD = {}


2 while(Pile 1 has more cards){
3 Read the top card X in Pile 1
4 itemD = updateDict(itemD, X)
5 Move X to Pile 2
6 }
7
8 foreach i in keys(itemD){
9 B = 0, items = []
10 foreach j in keys(itemD[i]){
11 if(itemD[i][j] == B){
12 items = items ++ [j]
13 }
14 if(itemD[i][j] > B){
15 B = itemD[i][j]
16 items = [j]
17 }
18 }
19 costD[i] = items
20 }
21
22 Procedure updateDict(D, Y)
23 if(not isKey(D, Y.ShopName)){
24 D[Y.ShopName] = {}
25 }
26 foreach A in Y.ItemList{
27 if(isKey(D[Y.ShopName], A.Item)){
28 D[Y.ShopName][A.Item] = D[Y.ShopName][A.Item] + A.Cost
29 }
30 else{
31 D[Y.ShopName][A.Item] = A.Cost
32 }
33 }
34 return(D)
35 End updateDict

Question 8 [4 Marks]
Statement
What will itemD[i][j] represent?
Options
(a)

Revenue generated by item j for shop i

(b)

Revenue generated by item i for shop j

(c)

Cost of item i in shop j

(d)

Cost of item j in shop i

Answer
Question 9 [5 Marks]
Statement
What will costD[i] represent at the end of the execution?

Options
(a)

List of item(s) which generated highest revenue for shop i

(b)

List of item(s) which generated lowest revenue for shop i

(c)

List of cost of most sold item(s) in shop i

(d)

List of cost of least sold item(s) in shop i

Answer
Question (10 - 11)
Statement
The followig pseudocode constructs a matrix M from the “Shopping Bills” dataset. Two bills are
said to be similar if the difference of their total bill amount is at most 100. Procedure abs(a)
returns absolute value of input intger a. For example: abs(5) = 5, abs(-5) = 5.

1 D = {}
2 while(Table 1 has more rows){
3 Read the first row X in Table 1
4 D[X.SeqNo] = [X.Name, X.Total]
5 Move X to Table 2
6 }
7
8 n = length(keys(D))
9 M = createMatrix(n, n)
10 foreach i in keys(D){
11 foreach j in keys(D){
12 if(i != j and abs(last(D[i]) - last(D[j]) <= 100){
13 M[i][j] = 1
14 if(first(D[i]) == first(D[j]){
15 M[i][j] = M[i][j] + 1
16 }
17 }
18 }
19 }

Question 10 [5 Marks]
Statement
Let i and j be the sequence numbers of two similar bills, where i j. Which of the following
statement(s) is/are are true about M[i][j]? It is a Multiple Select Question (MSQ).

Options
(a)

The maximum value of M[i][j] will be 2.

(b)

If M[i][j] = 1, then both the bills have same customer names

(c)

If M[i][j] = 1, then both the bills have different customer names


(d)

If M[i][j] = 2, then both the bills have same customer names

(e)

M[i][j] can be more than 2 if both the bills have same customer names

Answer
Question 11 [5 Marks]
Statement
Choose the correct statement(s) based on above pseudocode. It is a Multiple Select Question
(MSQ).

Options
(a)

For i j, if M[i][j] = 0 then M[j][i] = 1

(b)

For i j, if M[i][j] = 1 then M[j][i] = 1

(c)

For i j, if M[i][j] = 1 then M[j][i] = 0

(d)

For i j, if M[i][j] = 0 then M[j][i] = 0

(e)

For i j, if M[i][j] = 2 then M[j][i] = 2

Answer
Question 12 [5 Marks]
Statement
The following pseudocode is executed using the “Words” dataset. What will wList represent at the
end of execution?

1 A = 0
2 wList = [], L = []
3 while(Table 1 has more rows){
4 Read the first row X in Table 1
5 L = findSomething(L, X)
6 if(length(L) == A){
7 wList = wList ++ [X.Word]
8 }
9 if(length(L) > A){
10 A = length(L)
11 wList = [X.Word]
12 }
13 L = []
14 Move X to Table 2
15 }
16
17 Procedure findSomething(M, Y)
18 i = 1, t = ''
19 while(i <= Y.LetterCount){
20 t = ith letter of Y.Word
21 if(not member(M, t)){
22 M = M ++ [t]
23 }
24 i = i + 1
25 }
26 return(M)
27 End findSomething

Options
(a)

List of words which have maximum number of letters

(b)

List of words which have maximum number of distinct letters

(c)

List of words which have maximum number of duplicate letters


(d)

List of words which have minimum number of letters

Answer
Question 13 [6 Marks]
Statement
Let n be the number of rows in the "Words" dataset. A matrix W is constructed using the following
pseudocode.

1 W = createMatrix(n, n)
2 foreach i in rows(W){
3 foreach j in columns(W){
4 W[i][j] = []
5 }
6 }
7
8 while(Table 1 has more rows){
9 Read the first row X in Table 1
10 Move X to Table 2
11 while(Table 1 has more rows){
12 Read the first row Y in Table 1
13 Move Y to Table 3
14 if(X.Word != Y.Word and X.LetterCount == Y.LetterCount){
15 W[X.Seq No][Y.Seq No] = doSomething(X, Y)
16 }
17 }
18 Move all rows from Table 3 to Table 1
19 }
20
21 Procedure doSomething(A, B)
22 L = []
23 i = 1
24 while(i <= A.LetterCount){
25 p = ith letter of A.Word
26 j = 1
27 while(j <= B.LetterCount){
28 q = jth letter of B.Word
29 if(p == q and not(member(L, q)){
30 L = L ++ [q]
31 }
32 j = j + 1
33 }
34 i = i + 1
35 }
36 return(L)
37 End doSomething

For two different words i and j, what does the value W[i][j] represent at the end of the execution?

Option
(a)

List of distinct letters which are present in both words i and j with different letter counts

(b)

List of distinct letters which are not present in both words i and j with different letter counts

(c)

List of distinct letters which are present in both words i and j with same letter counts

(d)

List of distinct letters which are not present in both words i and j with same letter counts

Answer
Question 14 [6 Marks]
Statement
The following pseudocode is executed using the “Shopping Bills” dataset. At the end of the
execution, L stores the list of distinct shops from which only one category of items have been
bought. But the pseudocode may have mistakes. Identify all such mistakes (if any). Assume that
all statements not listed in the options below are free of errors. It is a Multiple Select Question
(MSQ).

1 A = {}
2 L = []
3 while(Pile 1 has more cards){
4 Read the top card X from Pile 1
5 if(not isKey(A, X.ShopName)){
6 A = updateDict(A, X)
7 }
8 else{
9 A[X.ShopName] = []
10 A = updateDict(A, X)
11 }
12 Move X to Pile 2
13 }
14 foreach k in keys(A){
15 if(length(A[k]) == 1){
16 L = L ++ [k]
17 }
18 }
19 Procedure updateDict(D, Y)
20 foreach Z in Y.ItemList{
21 if(not member(D, Z.Category)){
22 D[Y.ShopName] = D[Y.ShopName] ++ [Z.Category]
23 }
24 }
25 return(D)
26 End updateDict

Options
(a)

Line 1: Incorrect initialization of A

(b)

Line 5: Incorrect conditional statement

(c)

Line 16: Incorrect updating of L


(d)

Line 21: Incorrect conditional statement

(e)

Line 22: Incorrect updation of dictionary D

Answer
Question 15 [4 Marks]
Statement
What will the value of sum be at the end of the execution of following pseudocode? (NAT)

1 sum = 0
2 L1 = [3, 0, 2]
3 L2 = [1, -4, 5]
4 sum = addSomething(L1, L2) + addSomething(L2, L1)
5
6 Procedure addSomething(X, Y)
7 s = 0
8 foreach a in X{
9 foreach b in Y{
10 s = s + (a - b)
11 }
12 }
13 return(s)
14 End addSomething

Answer
Question 16 [5 Marks]
Statement
Let X and Y be two words from the "Words" table. The given procedure CountSentence counts
the number of sentences that do not contain both words X and Y. But the procedure may have
mistakes. Identify all such mistakes (if any). It is a Multiple Select Question (MSQ).

1 Procedure CountSentence(X, Y)
2 XCount = 0, YCount = 0, Count = 0
3 while(Table 1 has more rows){
4 Read the first row Z in Table 1
5 if(Z.Word == X){
6 XCount = XCount + 1
7 }
8 if(Z.Word == Y){
9 YCount = YCount + 1
10 }
11 if(Z.Word ends with a full stop){
12 if(XCount == 0 and YCount == 0){
13 Count = Count + 1
14 }
15 XCount = 0
16 YCount = 0
17 }
18 Move Z to Table 2
19 }
20 return(Count)
21 End CountSentence

Options
(a)

Line 6: Condition to increment XCount is incorrect

(b)

Line 9: Condition to increment YCount is incorrect

(c)

Line 13: Condition to increment Count is incorrect

(d)

Line 15&16: XCount and YCount are reinitialized with incorrect value

(e)

No error
Answer
Question-(17 - 19)
Statement
A computer scientist is planning to conduct an event in the city. She has come up with a novel
scheme to invite people:

The host (computer scientist) can send out any number of invitations and does not accept any
invitation.

Each invitation is represented by a unique text message.


Each invitee can choose to either accept or reject the invitation.
If an invitee accepts the invitation, then he can invite exactly one other person by forwarding
the invitation that he received to this person, i.e., the invitee can forward the message he
received only once.
If an invitee doesn't accept the invitation, he cannot invite anyone.
If a person receives multiple invitations, he can accept at most one of them. All other
invitations must be rejected.

This situation is modeled as a graph. There is a node corresponding to every person who attends
the event. n people attend the event and the attendees are indexed from 0 to . Given a pair
of attendees (i, j), there is an edge from i to j if and only if the following conditions are satisfied:

j was invited by i
j accepted i's invitation

The graph is represented by a matrix A, such that A[i][j] = 1 if and only if there is an edge from i to
j.

Consider the following graph of six attendees to the party:


Question-17 [2 Marks]
Statement
Who is the host? Enter a number between 0 and 5, both endpoints included.

Answer
Question-18 [3 Marks]
Statement
Which of the following statement(s) is/are true? It is a Multiple Select Question (MSQ).

Options
(a)

0 and 5 have identical messages

(b)

1, 2 and 5 have identical messages

(c)

1, 2 and 3 have identical messages

(d)

1 and 3 have different messages

(e)

2 and 5 have different messages

Answer
Question-19 [4 Mark]
Statement
Fill the missing values in the matrix representation A, of the above graph.

Options
(a)

a = 1, b = 1, c = 1, d = 0, e = 0

(b)

a = 1, b = 0, c = 1, d = 0, e = 0

(c)

a = 0, b = 0, c = 0, d = 1, e = 1

(d)

a = 0, b = 1, c = 1, d = 0, e = 1

Answer
Questions (20 - 21)
Statement
The following pseudocode constructs a graph G using the “Scores” dataset, represented by the
adjacency matrix B. Let A be a dictionary with sequence numbers of students as keys mapped to
their total marks.

1 n = length(keys(A))
2 B = createMatrix(n, n)
3
4 foreach i in keys(A){
5 foreach j in keys(A){
6 if(A[i] > A[j]){
7 B[i][j] = 1
8 }
9 }
10 }

Question - 20 [4 Marks]
Statement
Choose the correct option(s) with respect to the graph G. It is a Multiple Select Question (MSQ).

Options
(a)

The in-degree and out-degree for each node in G is the same.

(b)

G is always acyclic.

(c)

If B[i][j] = 1 then B[j][i] = 1, for any i, j

(d)

If B[i][j] = 1 then B[j][i] = 0, for any i, j

(e)

If B[i][j] = 0 then B[j][i] = 1, for any i, j


Answer
Question - 21 [4 Marks]
Statement
When will the procedure checkSomething(B, i) return True?

1 Procedure checkSomething(B, i)
2 foreach j in columns(B){
3 if((i != j) and (B[i][j] == 0)){
4 return(False)
5 }
6 }
7 return (True)
8 End checkSomething

Options
(a)

If student i has scored greater total marks than at least one student

(b)

If student i has scored less total marks than at least one student

(c)

If student i has scored lowest total marks among all students

(d)

If student i has scored highest total marks among all students

Answer
Question (22 - 23)
Statement
Let M be the adjacency matrix of the graph G given below.

1 Procedure updateMatrix(M)
2 tempMat = M
3 foreach i in rows(M){
4 foreach k in columns(M){
5 if(M[i][k] == 1){
6 foreach j in columns(M){
7 if(M[k][j] == 1){
8 tempMat[i][j] = 1
9 }
10 }
11 }
12 }
13 }
14 return(tempMat)
15 End updateMatrix

Based on above information, answer the following questions.

Question 22 [5 Marks]
Statement
What will be the value of B at the end of the execution of the pseudocode given below?

1 newMatrix = updateMatrix(M)
2 B = newMatrix[0][3]
Answer
Question 23 [4 Marks]
Statement
What will be the value of B at the end of execution of pseudocode given below?

1 newMatrix = updateMatrix(M)
2 newMatrix2 = updateMatrix(newMatrix)
3 B = newMatrix2[0][3]

Answer

You might also like