Question 1
Let L be a non-empty list, and D be a non-empty dictionary. Choose whether the given statements are true or false:
Elements of L can be lists.
TRUE
FALSE
The IIT Madras BS Computational Thinking (Computational Thinking (CT)) Quiz 2 paper sat on 13 Mar 2022, in the January 2022 term, set QPE2: 19 questions for 50 marks in 120 minutes. Every question is below with its answer. Take it as a timed mock test to be marked, or read it through first.
Let L be a non-empty list, and D be a non-empty dictionary. Choose whether the given statements are true or false:
Elements of L can be lists.
TRUE
FALSE
Correct answer
TRUE
Let L be a non-empty list, and D be a non-empty dictionary. Choose whether the given statements are true or false:
Let a be a key of dictionary D , then a must be an integer
TRUE
FALSE
Correct answer
FALSE
Let L be a non-empty list, and D be a non-empty dictionary. Choose whether the given statements are true or false:
For keys a and b in D , if a ≠ b then D [a] ≠ D[b] is always True.
TRUE
FALSE
Correct answer
FALSE
Let L be a non-empty list, and D be a non-empty dictionary. Choose whether the given statements are true or false:
For keys a and b in D , a ≠ b is always True.
TRUE
FALSE
Correct answer
TRUE
Let L be a non-empty list, and D be a non-empty dictionary. Choose whether the given statements are true or false:
For a key a in D , D [a] can be a dictionary.
TRUE
FALSE
Correct answer
TRUE
Let L be a non-empty list, and D be a non-empty dictionary. Choose whether the given statements are true or false:
Let D = { 3 : {‘a’: 5, ‘b’ : 4}, 5 : {‘c’ : 6}}, then the value of D [‘c’] is 6.
TRUE
FALSE
Correct answer
FALSE
Consider the procedure doSomething given below. If A = [4, 5, 3, 1, 9, 4, 6, 5, 9] and B = doSomething(A).
1 Procedure doSomething(A)2 outList = [first(A)]3 foreach X in rest(A) {4 if (X ≠ first(A)) {5 outList = outList ++ [X]6 }7 }8 return (outList)9 End doSomethingChoose the correct option.
B = [4, 5, 3, 1, 9, 6, 5, 9]
B = [4, 5, 3, 1, 9, 6]
B = [3, 1, 6]
B = [5, 3, 1, 9, 4, 6, 5, 9]
Correct answer
B = [4, 5, 3, 1, 9, 6, 5, 9]
The following table contains information regarding authors from the “Library” dataset. Each row in the table corresponds to an author and list of publication years. There are n authors, each author is being assigned a unique index between 0 and n−1.
The table is represented by a dictionary named authors, with S.No as keys and lists of publication years as values. Assume that authors has already been computed. For example, we have: authors [0] = [1998,..., 2015]
isCommon(L1, L2) returns True if there are at least two common elements in lists L1 and L2.
M = createMatrix (n, n)foreach i in keys (authors) { foreach j in keys (authors) { if (i > j and isCommon(authors[i], authors[j])) { M[i][j] = 1 M[j][i] = 1 } }}
A = { }foreach i in rows (M) { count = 0 foreach j in columns (M) { if (M[i][j] ≠ 0) { count = count + 1 } } A[i]= count}What does an entry A[i] represent at the end of the execution of the pseudocode above?
Author A[i] has published books in i years
Author i has published books in A[i] years
Author A[i] has published at least two books in common years with i authors
Author i has published at least two books in common years with A[i] authors
Correct answer
Author i has published at least two books in common years with A[i] authors
In a shop selling soft drinks, Ritvika wants to combine two soft drinks to see which combinations taste better. The drinks are labeled from 0 to n−1. To keep track of these combinations, she creates a matrix M. For drink i and j such that i ≠ j, if the combination of i and j tastes good, then M[i][j] = 1, otherwise 0. leastSuitable(M) returns the list of drinks which are least suitable for mixing with the maximum number of drinks. Choose the correct code fragment
Procedure leastSuitable(M) min = 10000 minList = [ ] foreach i in rows(M) { k = 0 ******************** * Fill the code * ******************** } return (minList)End leastSuitableCorrect answer
Consider the procedure given below.
Procedure eliminate (L1, L2) L3 = [ ], Found = False foreach i in L2 { foreach j in L1 { if (i == j) { Found = True } } if (not Found) { L3 = L3 ++ [i] } Found = False } return (L3)End eliminateIf L1 and L2 are two lists, and L = eliminate (L1, L2), then answer the given subquestions.
What will L represent?
It will contain all elements of L2 that are not present in L1.
It will contain all elements of L1 that are not present in L2 .
It will contain the elements common to L1 and L2 .
It will contain the elements present in L1 or L2 but not both.
Correct answer
It will contain all elements of L2 that are not present in L1.
Consider the procedure given below.
Procedure eliminate (L1, L2) L3 = [ ], Found = False foreach i in L2 { foreach j in L1 { if (i == j) { Found = True } } if (not Found) { L3 = L3 ++ [i] } Found = False } return (L3)End eliminateIf L1 and L2 are two lists, and L = eliminate (L1, L2), then answer the given subquestions.
Which of the following option(s) is/are always correct? It is a Multiple Select Question (MSQ).
length(L2) − length(L1 ) = length(L)
length(L2) > length(L1)
length(L2) ≥ length(L)
length(L1 ) ≤ length(L)
Correct answer
length(L2) ≥ length(L)
What will countSomething(M, 0, 5) return?
NOTE: Enter your answer to the nearest integer.
Correct answer: 1
If Line 2 is replaced by count = M[i][j], then what will countSomething(M, 0, 5) return? NOTE: Enter your answer to the nearest integer.
Correct answer: 1
The following pseudocode is executed using the “Words” dataset. Assume that words are arranged in increasing order of sequence number.
B = 0sList = [ ], wList = [ ]while (Table 1 has more rows) { Read the first row X in Table 1 Move X to Table 2 wList = wList ++ [X.PartOfSpeech] if (X.Word ends with a full stop) { A = doSomething(wList) if (A > B) { B = A } sList = sList ++ [wList] wList = [ ] }}Procedure doSomething(L) count = 0 foreach p in L { if (p == "Noun") { count = count + 1 } } return(count)End doSomethingBased on the above data, answer the given subquestions.
What will B represent at the end of the execution?
Maximum number of nouns in a sentence across all sentences.
Total number of nouns across all sentences.
Minimum number of nouns in a sentence across all sentences.
Number of sentences having maximum number of nouns.
Correct answer
Maximum number of nouns in a sentence across all sentences.
The following pseudocode is executed using the “Words” dataset. Assume that words are arranged in increasing order of sequence number.
B = 0sList = [ ], wList = [ ]while (Table 1 has more rows) { Read the first row X in Table 1 Move X to Table 2 wList = wList ++ [X.PartOfSpeech] if (X.Word ends with a full stop) { A = doSomething(wList) if (A > B) { B = A } sList = sList ++ [wList] wList = [ ] }}Procedure doSomething(L) count = 0 foreach p in L { if (p == "Noun") { count = count + 1 } } return(count)End doSomethingBased on the above data, answer the given subquestions.
What will length(sList) represent at the end of execution.
Total number of words in “Words” dataset
Total number of sentences in “Words” dataset
Total number of words with same part of speech in “Words” dataset
Total number of words with different part of speech in “Words” dataset
Correct answer
Total number of sentences in “Words” dataset
The following pseudocode is executed using the “Shopping Bills” dataset.
D = { }while (Pile 1 has more cards) { Read the top card X in Pile 1 foreach a in X.ItemList { if (isKey(D, a.Category)) { if (isKey(D[a.Category], a.ItemName)) { D[a.Category][a.ItemName] = D[a.Category][a.ItemName] ++ [a.Price] } else { D[a.Category][a.ItemName] = [a.Price] } } else { D[a.Category] = { } D[a.Category][a.ItemName] = [a.Price] } } Move card X to Pile 2}Based on the above data, answer the given subquestions.
What will each value D[i][j] represent at the end of the execution?
Price of item i of category j across all bills
Price of item j of category i across all bills
List of prices of item i of category j across all bills
List of prices of item j of category i across all bills
Correct answer
List of prices of item j of category i across all bills
The following pseudocode is executed using the “Shopping Bills” dataset.
D = { }while (Pile 1 has more cards) { Read the top card X in Pile 1 foreach a in X.ItemList { if (isKey(D, a.Category)) { if (isKey(D[a.Category], a.ItemName)) { D[a.Category][a.ItemName] = D[a.Category][a.ItemName] ++ [a.Price] } else { D[a.Category][a.ItemName] = [a.Price] } } else { D[a.Category] = { } D[a.Category][a.ItemName] = [a.Price] } } Move card X to Pile 2}Based on the above data, answer the given subquestions.
Using the dictionary D created in the previous question, what will the value of L represent at the end of the execution of the pseudocode below?
A = 100000, L = [ ]foreach i in keys(D) { foreach j in keys(D[i]) { data = findRange(D[i][j]) B = first(data) - last(data) if (B == A) { L = L ++ [j] } if (B < A) { A = B L = [j] } }}
Procedure findRange(Y) p = 0, q = 100000 foreach k in Y{ if (k > p) { p = k } if (k < q) { q = k } } return([p, q])End findRangeList of items for which the difference between the highest and lowest price is the same
List of items for which the difference between the highest and lowest price is maximum
List of items for which the difference between the highest and lowest price is minimum
List of items with same price in all shops
Correct answer
List of items for which the difference between the highest and lowest price is minimum
The following pseudocode is executed using the “Shopping Bills” dataset. Procedure similar(X, Y) returns True if the difference between X and Y is less than 100.
A = { }while (Pile 1 has more cards) { Read the top card X in Pile 1 A[X.Seq_No] = [X.ShopName, X.Total] Move card X to Pile 2}n = length(keys(A))S = CreateMatrix(n, n)foreach i in keys(A) { foreach j in keys(A) { if (i > j and isPair(A[i], A[j])) { S[i][j] = 1 S[j][i] = 1 } }}Procedure isPair(P, Q) if (first(P) ≠ first(Q) and similar(last(P), last(Q))) { return (True) } else { return (False) }End isPairA graph is constructed using matrix S created by the above pseudocode. Based on the given information answer the subquestions.
Choose the correct statement(s). It is a Multiple Select Question (MSQ).
Correct answers
The following pseudocode is executed using the “Shopping Bills” dataset. Procedure similar(X, Y) returns True if the difference between X and Y is less than 100.
A = { }while (Pile 1 has more cards) { Read the top card X in Pile 1 A[X.Seq_No] = [X.ShopName, X.Total] Move card X to Pile 2}n = length(keys(A))S = CreateMatrix(n, n)foreach i in keys(A) { foreach j in keys(A) { if (i > j and isPair(A[i], A[j])) { S[i][j] = 1 S[j][i] = 1 } }}Procedure isPair(P, Q) if (first(P) ≠ first(Q) and similar(last(P), last(Q))) { return (True) } else { return (False) }End isPairA graph is constructed using matrix S created by the above pseudocode. Based on the given information answer the subquestions.
There will be an edge between bills i and j if:
It is a Multiple Select Question (MSQ).
The total bill amount of i is lower than the total bill amount of j by less than 100 and both bills are from the different shops.
The total bill amount of i is greater than the total bill amount of j by less than 100 and both bills are from the different shops.
The total bill amounts of bills i and j are same but both bills are from the different shops.
The total bill amounts of bills i and j are same and both bills are from the same shop.
Correct answers
The total bill amount of i is lower than the total bill amount of j by less than 100 and both bills are from the different shops.
The total bill amount of i is greater than the total bill amount of j by less than 100 and both bills are from the different shops.
The total bill amounts of bills i and j are same but both bills are from the different shops.