Skip to content

CT Week 2 Graded Assignments IIT Madras

Use the following flowchart to answer the below two questions 1) and 2).

2 points
If the Correct Card is found after 11 iterations of Another Card, the Correct Card is the 11th , then what is the value of Count-Cards?
2 points
Let’s use the Scores dataset and the Correct Card is the user’s requirement. How many possible score-cards does the iteration go through if the user requirement is found in the First Card and all other cards do not match?
3 points
The following procedure finds the minimum marks in Chemistry scored by a Male student from the Scores dataset. However, the programmer may have made mistakes in one or more steps. Identify any such steps (if any).

Step 1: Arrange all cards in a single pile called Pile 1
Step 2: Maintain a variable MIN-CHEMISTRY and initialize with first Chemistry
SCORE where Gender = M
Step 3: If Pile 1 is empty then stop the iteration
Step 4: Read the top card of Pile 1
Step 5: If Gender == M and Chemistry ≥ MIN-CHEMISTRY
Step 6: Update Chemistry = MIN-CHEMISTRY
Step 7: Move the current card to Pile 2 and repeat from step 3
3 points
A programmer has written the following algorithm to find the number of students who are below the Avg- Marks in Scores dataset. He/she committed a mistake. Can you identify it?

Step 1: Arrange all cards cards in Pile 1
Step 2: Calculated Average marks are stored into Avg-Marks.
Step 3: Initialize Student-Count with 0
Step 4: Stop iteration, when Pile 1 is empty
Step 5: Read one top card from Pile 1
Step 6: If Avg-Marks ≤ TOTAL then add value 1 to Student-Count
Step 7: Move the current card to Pile 2 and repeat Step 4
The shopping bill dataset contains Shop Names [Big Bazar, SV Stores, Sun General, More Supermarket]. The programmer wants to find out the store-wise minimum bill amount. How many variables are required?
3 points
Assume that there are 5 cards in the Paragraph words dataset [’ It’, ’is’, ’a’, ’rainy’, ’Monday.’]. What is the value of A after the below algorithm is executed?

Step 1: Arrange all cards in Pile 1, cards repeated
Step 2: Initialize A with 10
Step 3: Stop iteration, when Pile 1 is empty
Step 4: Read one top card from Pile 1
Step 5: If A ≥ LetterCount then Update A = LetterCount
Step 6: Move the current card Pile 2 and repeat Step 3
3 points
2 points
If X is a card from the Shopping Bill dataset. Identify the list of fields that can be accessed through card X
3 points
Which of the following is the correct pseudocode to find the longest verb length in the Paragraph Words dataset?
2 points
To find out the Minimum Total Marks in Scores dataset. Recommended initial value of Min-Total-Marks variable
2 points
Match the following using the pseudocode concept 
Column 1                      Column 2
a) ==                                i) True
b) =                                  ii) Equality
c) 56 ≥ 7                           iii) Assignment

Computational Thinking week 2 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 procedure is executed using the “Scores” dataset. At the end of the execution, diff stores the difference between the highest and lowest total marks. The programmer may have made mistakes in one or more steps. Identify all such steps (if any). Assume that all the steps not mentioned in options are free from errors. It is a Multiple Select Question (MSQ).
    Step 1. Arrange all cards in a single pile called Pile 1
    Step 2. Initialize variables max to 0, min to 300, and diff to 0
    Step 3. If Pile 1 is empty then go to step 8
    Step 4. Read the top card in Pile 1
    Step 5. If Total < max then store Total in max
    Step 6. If Total < min then store Total in min
    Step 7. Move the current card to another pile called Pile 2 and repeat from step 3
    Step 8. Update value of diff to (max – min) 
 
2.  Match the following expressions in the Column 1 with the appropriate values in column 2.
 
3. The following procedure is executed using “Words” dataset. What will A represent at the end of the execution?
Step 1. Arrange all cards in a single pile called Pile 1
Step 2. Maintain two variables A, B and initialize them to 0
Step 3. If Pile 1 is empty then stop the iteration
Step 4. Read the top card in Pile 1
Step 5. Increment variable B
Step 6. If Word does not end with a full stop then execute step 9
Step 7. If Word ends with a full stop and B > A then store B in A
Step 8. Re-initialize the variable B to 0
Step 9. Move the current card to another pile called Pile 2 and repeat from step 3
 

4.  The following procedure is executed using “Words” dataset. What will A and B represent at the end of the execution?
Step 1. Arrange all cards in a single pile called Pile 1
Step 2. Maintain two variables A, B and initialize them to 100000
Step 3. If Pile 1 is empty then stop the iteration
Step 4. Read the top card in Pile 1
Step 5. If Mathematics Marks < A, then store A in B and Mathematics Marks in A
Step 6. If Mathematics Marks > A and Mathematics Marks < B, then store Mathematics Marks in B
Step 7. Move the current card to another pile called Pile 2 and repeat from step 3

 
5.  The given procedure is executed using the “Scores” dataset. Kajal and Rashmita both have scored the lowest mark in Physics which is 37. Let all the cards be arranged in a single pile called Pile 1 in such a way that Kajal’s card is below Rashmita’ s card. What will the values of A and B be at the end of the execution?
Step 1. Maintain two variables A and B and initialize them to 101 and “None” respectively
Step 2. If Pile 1 is empty then stop the iteration
Step 3. Read the top card in Pile 1
Step 4. If Physics marks <= A, then store Physics marks in A and store student’s name in B
Step 5. Move the current card to another pile called Pile 2 and repeat from step 2
 
6.  The following pseudocode is executed using the “Scores” dataset. What will count represent at the end of the execution of pseudocode?


 

7.  he following procedure is executed using “Scores” dataset. What will X and Y represent at the end of the execution?
Step 1. Arrange all cards in a single pile called Pile 1
Step 2. Maintain variables A, B, Y and Initialize them to 0
Step 3. Maintain a variable X and initialize it to “None”
Step 4. If Pile 1 is empty then stop the iteration
Step 5. Read the top card in Pile 1
Step 6. If the Gender is ‘F’ then add one to A. If A > Y then store A in Y and “Female” in X
Step 7. If the Gender is ‘M’ then add one to B. If B > Y then store B in Y and “Male” in X
Step 8. Move the current card to another pile called Pile 2 and repeat from step 4

 
8.  The given pseudocode is executed using the “Words” dataset. At the end of the execution, count finds the number of sentences with least number of words. Choose the correct option to complete the pseudocode
 
9.  The following pseudocode is executed using the “Words” dataset. At the end of the execution, A captures the minimum letter count of an adjective. Choose the correct code fragment(s) to complete the pseudocode. It is Multiple Select Question (MSQ).

     

Add Your Heading Text Here

index

Week-2, Graded


Week-2, Graded
Question 1 [2 Marks]

Statement
Options

(a)

(b)

(c)

(d)

(e)
Answer
Solution

Question-2 [2 Marks]
Statement
Options

(a)

(b)

(c)

(d)
Answer
Solution

Question-3 [3 Marks]
Statement
Options

(a)

(b)

(c)

(d)
Answer
Solution

Question-4 [3 Marks]
Statement
Options

(a)

(b)

(c)

(d)
Answer
Solution

Question-5 [3 Marks]
Statement
Options

(a)

(b)

(c)

(d)
Answer
Solution

Question-6 [3 Marks]

Statement
Options

(a)

(b)

(c)

(d)
Answer
Solution

Question-7 [3 Marks]
Statement
Options

(a)

(b)

(c)

(d)
Answer
Solution

Question-8 [3 Marks]
Statement
Options

(a)

(b)

(c)

(d)
Answer
Solution

Question-9 [3 Marks]
Statement
Options

(a)

(b)

(c)

(d)
Answer
Solution

Question-10 [3 Marks]
Statement
Options

(a)

(b)

(c)

(d)
Answer
Solution


Question 1 [2 Marks]

Statement

The following procedure is executed using the "Scores" dataset. At the end of the execution, diff stores the
difference between the highest and lowest total marks. The programmer may have made mistakes in one or
more steps. Identify all such steps (if any). Assume that all the steps not mentioned in options are free from
errors. It is a Multiple Select Question (MSQ).

Step 1. Arrange all cards in a single pile called Pile 1

Step 2. Initialize variables max to 0, min to 300, and diff to 0
Step 3. If Pile 1 is empty then go to step 8

Step 4. Read the top card in Pile 1

Step 5. If Total < max then store Total in maxStep 6. If Total < min then store Total in min

Step 7. Move the current card to another pile called Pile 2 and repeat from step 3
Step 8. Update value of
diff to (max - min)

Options

(a)

Step 2: Incorrect initialization of variable max

(b)

Step 2: Incorrect initialization of variable min

(c)

Step 3: The statement should be "If Pile 1 is empty then stop the iteration"

(d)

Step 5: Incorrect conditional statement to update max

(e)

No mistake

Answer

(d)

Solution

In the given procedure we want to find the difference between the maximum total marks secured and
minimum total marks secured. For this, the procedure is storing the maximum mark in
max and minimum
marks in
min. In step 5, if the Total marks are more than max (as we see that in step 1, max is initialized to
0), the the value of
max will be updated. The correct conditional statement should have been, " If Total >max then store Total in max " Then only we can say that max is storing the maximum total marks. But in the
given procedure, "if
Total is less than max then Total is stored in max" which results in never updating the
value of
max. Therefore, option (d) is correct.

Question-2 [2 Marks]

Statement

Match the following expressions in the Column 1 with the appropriate values in column 2.


Column 1

Column 2

a. 4 == 4 or 2 < 6

1. Invalid expression

b. 2 == 2 and 2 > 5

2. True

c. 8 = 3

3. False

d. 45 + '2'

4. 47

e. 2 < 3

5. "47"


Options

(a)

a - (2), b - (3), c - (1), d - (4), e - (2)

(b)

a - (2), b - (3), c - (1), d - (5), e - (2)

(c)

a - (2), b - (3), c - (1), d - (1), e - (2)

(d)

a - (1), b - (3), c - (2), d - (1), e - (1)

Answer

(c)

Solution

4 == 4 - True , 2 < 6 - True. Therefore, True or True = True. (a. maps to 2.)

2 == 2 - True, 2 > 5 - False. Therefore, True and False = False. (b. maps to 3.)

8 = 3 - Invalid expression, Assignment is for variables not the values(like integer,
strings, etc)
(c. maps to 1.)

45 + '2' - Invalid expression, Addition of two different data types is not possible. (d. maps to 1.)2 < 3 - True. (a. maps to 2.)

Question-3 [3 Marks]

Statement

The following procedure is executed using "Words" dataset. What will A represent at the end of the
execution?

Step 1. Arrange all cards in a single pile called Pile 1

Step 2. Maintain two variables A, B and initialize them to 0
Step 3. If Pile 1 is empty then stop the iteration

Step 4. Read the top card in Pile 1
Step 5. Increment variable
B

Step 6. If Word does not end with a full stop then execute step 9

Step 7. If Word ends with a full stop and B > A then store B in AStep 8. Re-initialize the variable B to 0

Step 9. Move the current card to another pile called Pile 2 and repeat from step 3

Options

(a)

Length of the shortest sentence based on the number of words

(b)

Length of the longest sentence based on the number of words

(c)

Length of the longest sentence based on the number of letters

(d)

Length of the shortest sentence based on the number of letters

Answer

(b)

Solution

Step 5: B stores the sum of the words but how many words?

Step 6: It says if the word does not end with full stop then go to step 9 which is nothing but repeating the
iteration. It means when a word ends with a full stop, then step 7 and 8 will be executed. From step 8 it is
clear that whenever the word ends with a full stop then
B is being reinitialized to 0. This means B stores the
word counts in a sentence.

Step 7: For every sentence, A is compare with B. The value of A gets updated with the value of B whenever Bis greater than A.

As A is initialized with 0, and B stores the number of words in a sentence, A stores the maximum words in a
sentence i.e., length of longest sentence in terms of number of words.

Question-4 [3 Marks]

Statement

The following procedure is executed using "Words" dataset. What will A and B represent at the end of the
execution?

Step 1. Arrange all cards in a single pile called Pile 1

Step 2. Maintain two variables A, B and initialize them to 100000
Step 3. If Pile 1 is empty then stop the iteration

Step 4. Read the top card in Pile 1

Step 5. If Mathematics Marks < A, then store A in B and Mathematics Marks in A

Step 6. If Mathematics Marks > A and Mathematics Marks < B, then store Mathematics Marks in BStep 7. Move the current card to another pile called Pile 2 and repeat from step 3

Options

(a)

A = Highest mark in Mathematics and B = Lowest mark in Mathematics

(b)

A = Lowest mark in Mathematics and B = Highest mark in Mathematics

(c)

A = Highest mark in Mathematics and B = Second highest mark in Mathematics

(d)

A = Lowest mark in Mathematics and B = Second lowest mark in Mathematics

Answer

(d)

Solution

Let us take the first 10 Mathematics marks from dataset. From step 5 and 6 it is clear that we only need the
Mathematics marks of students (cards).

The Mathematics marks of first five students are 68, 62, 57, 42 and 87.
First card:

Step 5: If we pick the first card with CardNo 0, the Mathematics mark is 68. As 68 is less than 100000 (the
current value of
A), B will store the value of A therefore, the value of B will be 100000 and A will be updated
with 68. Therefore, the current value of
A and B are 68 and 100000 respectively.

Step 6: Mathematics mark is not greater than A, step 6 will not be executed.
Second Card:

Step 5: The Mathematics mark is 62 which is less than 68 therefore, step 5 will be executed. A will be
updated with current
Mathematics marks and B will be updated with A. Therefore, the current value of Aand B are 62 and 68 respectively.

Step 6: Mathematics mark is not greater than A, step 6 will not be executed.
Third card

Step 5: The Mathematics mark is 57 which is less than 62 therefore, step 5 will be executed. A will be

updated with current Mathematics marks and B will be updated with A. Therefore, the current value of Aand B are 57 and 62 respectively.

Step 6: Mathematics mark is not greater than A, step 6 will not be executed.
Fourth card

Step 5: The Mathematics mark is 42 which is less than 57 therefore, step 5 will be executed. A will be

updated with current Mathematics marks and B will be updated with A. Therefore, the current value of Aand B are 42 and 57 respectively.

Step 6: Mathematics mark is not greater than A, step 6 will not be executed.

From the first three cards having Mathematics marks 68, 62, 57 and 42, it is clear that A stores the lowest
marks in
Mathematics whereas B stores the second lowest marks in Mathematics

Question-5 [3 Marks]

Statement

The given procedure is executed using the “Scores” dataset. Kajal and Rashmita both have scored the lowest
mark in
Physics which is 37. Let all the cards be arranged in a single pile called Pile 1 in such a way that
Kajal's card is below Rashmita' s card. What will the values of
A and B be at the end of the execution?

Step 1. Maintain two variables A and B and initialize them to 101 and "None" respectively
Step 2. If Pile 1 is empty then stop the iteration

Step 3. Read the top card in Pile 1

Step 4. If Physics marks <= A, then store Physics marks in A and store student's name in BStep 5. Move the current card to another pile called Pile 2 and repeat from step 2

Options

(a)

A = 37, B = "Rashmita"

(b)

A = 37, B = "Kajal"

(c)

A = "Kajal", B = 37

(d)

A = "Rashmita", B = 37

Answer

(b)

Solution

Step 4: If the Physics marks of the picked card is less than or equal to A, A will be updated with the current
Physics marks of the picked card and simultaneously the student ' s name will be stored in B. Now let after a
certain iterations,

image

Let us assume that, A = z where and B = "xyz"

As Kajal's card is below Rashmita 's card, Rashmita's card will be picked up first. As 37 is less than or equal to
the current value of
A (as it is mentioned in the question that 37 is the minimum marks), A will be updated
with 37 and
B will be updated with "Rashmita".

Now Kajal's card will be picked up. 37 is equal to the current value of A which is 37, Step 4 will be executed
and the values of
A and B will change to 37 and "Kajal" respectively.

Therefore, A = 37 and B = "Kajal".

Question-6 [3 Marks]

Statement

The following pseudocode is executed using the “Scores” dataset. What will count represent at the end of
the execution of pseudocode?


count = 0

while(Pile 1 has more cards){

Read the top card X from Pile 1
C = True

if(X.Mathematics < 56){
C = False

}

if(X.Physics < 56){
C = False

}

if(X.Chemistry < 56){
C = False

}

if(C == True){

count = count + 1

}

Move X to Pile 2

}


Options

(a)

Number of students who scored more than 56 marks in all three subjects

(b)

Number of students who scored less than 56 marks in all three subjects

(c)

Number of students who scored less than 55 marks in all three subjects

(d)

Number of students who scored more than 55 marks in all three subjects

Answer

(d)

Solution

The question is about finding what C represents? From the condition given in the line 14 it is clear that
count totally depends on the value of C. Whenever C is true, count is being incremented. So it is clear that
count represents the number of times C is being true.

Now let us focus on when C is true? C is initialized to True at the start. In the line 5, it is said that C will be
false whenever the Mathematics mark is less than 56. It means
C will be true if Mathematics marks is
greater than 55. From line 8, it is clear that
C is also being false whenever Physics marks are less than 56.
That means if
C is true, then the student in the selected card has scored more than 55 in Physics. Similarly
from line 11, it is also clear that
C is true whenever students scores more than 55 in Chemistry. So if any of
the conditions become true, that is student has scored less than 56 in either Mathematics or Physics or
Chemistry,
C will be False. Otherwise, it is true. Which means count is the number of Students who have
scored more than 55 in all the subjects.

Question-7 [3 Marks]

Statement

The following procedure is executed using "Scores" dataset. What will X and Y represent at the end of the
execution?

Step 1. Arrange all cards in a single pile called Pile 1
Step 2. Maintain variables
A, B, Y and Initialize them to 0
Step 3. Maintain a variable
X and initialize it to “None”
Step 4. If Pile 1 is empty then stop the iteration

Step 5. Read the top card in Pile 1

Step 6. If the Gender is 'F' then add one to A. If A > Y then store A in Y and “Female" in XStep 7. If the Gender is 'M' then add one to B. If B > Y then store B in Y and “Male” in XStep 8. Move the current card to another pile called Pile 2 and repeat from step 4

Options

(a)

X : "Male"

Y : 17

(b)

X : "Female"

Y : 17

(c)

X : "Female"

Y : 13

(d)

X : "Male"
Y : 13

Answer

(a)

Solution

Here in step 2, variables A, B and Y are initialized to 0 whereas in step 3, variable X is initialized to ”None”
which indicates that this variable is used to store value of string datatype. If we observe steps 6 and 7 then
we can notice that the computation in these steps is identical except it is for different gender.

Variables A and B store the number of cards from 'F' and 'M' respectively. Variable Y stores maximum
between
A and B. This step also stores the gender which corresponds to the maximum in the variable X.
Here is the full list of cards which belong to the respective cities.


Gender

Card No.

Total no. of cards

F

3,4,5,10,12,14,15,18,21,22,23,25,28

13

M

0,1,2,6,7,8,9,11,13,16,17,19,20,24,26,27,29

17

Question-8 [3 Marks]

Statement

The given pseudocode is executed using the “Words” dataset. At the end of the execution, count finds the
number of sentences with least number of words. Choose the correct option to complete the pseudocode.


count = 0, A = 0, B = 100000

while(Pile 1 has more cards){

Read the top card X from Pile 1
A = A + 1

if(X.Word ends with full stop){
if(A == B){

*** Statement 1 ***

}

if(A < B){

B = A

*** Statement 2 ***

}

A = 0

}

Move X to Pile 2

}


Options

(a)

Statement 1: count = 1, Statement 2: A = A + 1

(b)

Statement 1: count = 1, Statement 2: count = count + 1

(c)

Statement 1: count = count + 1, Statement 2: count = 1

(d)

Statement 1: count = count + 1, Statement 2: A = 1

Answer

(c)

Solution

In the question, count is supposed to find the number of sentences with least number of words in it.
Therefore,
count should be initialized to 0. Along with count, we need two more other variables, one to
keep track of the number of words in the current sentence. This is being done by the variable
A. Second
variable to keep track of the number of least words in a sentence seen till now. From the pseudocode it is

clear that this job is being done by the variable B.

Remember, there could be more sentences having the least number of words. Therefore, whenever we find
the next least,
B should be updated with the minimum number of words in a sentence. Next, if we find the
same number of words in the different sentence (i.e., equal to the current minimum)
count should be
incremented. In Line 10,
B is being updated whenever the next minimum is being found. Simultaneously,
count should also be initialized to one. Therefore, Statement 2: count = 1. For counting number of
sentences with same minimum number of words
count should be incremented whenever we find the
sentence with same min words and therefore, Statement 1:
count = count + 1

Question-9 [3 Marks]

Statement

The following pseudocode is executed using the “Words” dataset. At the end of the execution, A captures
the minimum letter count of an adjective. Choose the correct code fragment(s) to complete the
pseudocode. It is Multiple Select Question (MSQ).


1. A = 100

  1. while(Pile 1 has more cards){

  2. Read the Top card X in Pile 1

4. *********************

5. * Fill the code *

6. *********************

7. Move X to Pile 2
8.
}


Options

(a)


  1. if(X.PartOfSpeech == “Adjective” and X.LetterCount > A){

  2. A = X.LetterCount
    3. }


(b)


  1. if(X.PartOfSpeech == “Adjective” and X.LetterCount < A){

  2. A = X.LetterCount
    3. }


(c)


  1. if(X.PartOfSpeech == “Adjective”){

  2. if(X.LetterCount > A){

  3. A = X.LetterCount
    4. }

5. }


(d)


  1. if(X.PartOfSpeech == “Adjective”){

  2. if(X.LetterCount < A){

  3. A = X.LetterCount
    4. }

5. }

Answer

(b), (d)

Solution

From the question, it is clear that A stores the minimum number of letters in an Adjective. At the start of
pseudocode,
A is initialized to 0. To find the minimum letter count of an adjective, we know that A should be
compared to the number of letters in the word. Whenever the part of speech of a word is adjective and the
number of letters in the word is less than
A, A should be updated with the letter count. Therefore, there are
two conditions to be followed. First, the picked word should be an adjective and second, the letter count of
this adjective should be less than
A (i.e., is the current value of A). These two conditions are found in options
in (b) and (d).

Question-10 [3 Marks]

Statement

The following pseudocode is executed using the “Olympics” dataset. At the end of the execution, A captures
the number of players who have won a "Gold" medal but are not Indians. Choose the INCORRECT code
fragment(s) that cannot be used to complete the pseudocode. It is Multiple Select Question (MSQ).


1. A = 0

  1. while(Pile 1 has more cards){

  2. Read the Top card X in Pile 1

4. *********************

5. * Fill the code *

6. *********************

7. Move X to Pile 2
8.
}


Options

(a)


1. if(X.Medal == “Gold” and X.Nationality != "Indian"){
2. A = 1

3. }


(b)


1. if(X.Medal == “Gold” and X.Nationality != "Indian"){
2. A = A + 1

3. }


(c)


  1. if(X.Medal == “Gold”){

  2. if(X.Nationality != "Indian"){
    3. A = A + 1

4. }

5. }


(d)


  1. if(X.Nationality != "Indian"){

  2. if(X.Medal == “Gold”){
    3. A = A + 1

4. }

5. }

Answer

(a)

Solution

From the question, it is clear that A stores the number of players in who have won a "Gold" medal and are
not from India. From the options, it is clear that (b), (c), and (d) are the correct code fragments. In option (a),
the condition to check is correct , however the value of
A is wrongly updated to one always. Hence, option

(a) has incorrect code fragment. Therefore, option (a) is the correct answer.

12 thoughts on “CT Week 2 Graded Assignments IIT Madras”

  1. Hey There. I found your blog using msn. This is
    a very well written article. I will make sure to bookmark
    it and come back to read more of your useful information. Thanks for the post.
    I’ll certainly comeback.

  2. Woah! I’m really loving the template/theme of this website.
    It’s simple, yet effective. A lot of times it’s difficult to get that “perfect balance” between superb usability
    and visual appearance. I must say you’ve done a
    very good job with this. In addition, the blog loads super fast
    for me on Firefox. Excellent Blog!

  3. I blog often and I really thank you for your content. The article has truly
    peaked my interest. I am going to bookmark your site and keep checking for new information about once per week.
    I subscribed to your RSS feed too.

  4. I do not even know how I ended up here, but I thought this post
    was great. I don’t know who you are but definitely you are going to a famous blogger if you are
    not already 😉 Cheers!

  5. whoah this blog is excellent i like studying your posts.
    Stay up the great work! You already know, many persons are searching round for this information, you can aid them greatly.

Leave a Reply

Your email address will not be published. Required fields are marked *

Tags: