Week 8 - Graded Assignment 8 - (Sep 2025 - CT - Qualifier)

The due date for submitting this assignment has passed. Due on 2025-11-19, 23:59 IST. You may submit any number of times before the due date. The final submission will be considered for grading.

Last Submitted: You have last submitted on: 2025-11-19, 19:18 IST

Note: ++++++++++++++++++++++++++++++++++


Question 1

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

xxxxxxxxxx

1

D = {}

2

while(Table 1 has more rows){

3

    Read the fist row X in Table 1

4

    if(isKey(D, X.Town/City)){

5

        if(D[X.Town/City] > X.Mathematics){

6

            D[X.Town/City] = X.Mathematics

7

        }

8

    }

9

    else{

10

        D[X.Town/City] = X.Mathematics

11

    }

12

    Move X to Table 2

13

}

14

15

A = 0, B = 100

16

foreach Y in keys(D){

17

    if(B == D[Y]){

18

        A = A + 1

19

    }

20

    if(B > D[Y]){

21

        A = 1

22

        B = D[Y]

23

    }

24

}
  • A = Cities where students score the highest marks in Mathematics B = The highest marks in Mathematics
  • A = Number of cities where students score the highest marks in Mathematics B = The highest marks in Mathematics
  • A = Number of cities where students score the lowest marks in Mathematics B = The lowest marks in Mathematics
  • A = Always more than one B = The highest marks in Mathematics

Status: Yes, the answer is correct. Score: 3

Accepted Answers:

  • A = Number of cities where students score the lowest marks in Mathematics
    B = The lowest marks in Mathematics

Question 2

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

xxxxxxxxxx

1

D = {}, B = 0

2

while(Table 1 has more rows){

3

    Read the first row X in Table 1

4

    D = updateDictByField(D, X.Physics)

5

    Move X to Table 2

6

}

7

B = findAKey(D

8

9

Procedure updateDictByField(D, Value)

10

    if(isKey(D, Value)){

11

        D[Value] = D[Value] + 1

12

    }

13

    else{

14

        D[Value] = 1

15

    }

16

    return(D)

17

End updateDictByField

18

19

Procedure findAKey(D)

20

    Key = -1, Value = 0

21

    foreach A in keys(D){

22

        if(D[A] > Value){

23

            Value = D[A]

24

            Key = A

25

        }

26

    }

27

    return(Key)

28

End findAKey
  • Number of repeated marks in Physics
  • Minimum marks in Physics
  • Maximum marks in Physics
  • Most frequent marks in Physics

Status: Yes, the answer is correct. Score: 4

Accepted Answers:

  • Most frequent marks in Physics

Question 3

The following pseudocode is executed using the “Scores” dataset. What will be the value of B at the end of the execution?

xxxxxxxxxx

1

D = {"Mathematics": {}, "Physics": {}, "Chemistry": {}}, B = 0

2

while(Table 1 has more rows){

3

    Read the first row X in Table 1

4

    D = updateDictByField(D, X, "Mathematics")

5

    D = updateDictByField(D, X, "Physics")

6

    D = updateDictByField(D, X, "Chemistry")

7

    Move X to Table 2

8

}

9

10

while(Table 2 has more rows){

11

    Read the first row X in Table 2

12

    if(eligible(D, X) > 1){

13

        B = B + 1

14

    }

15

    Move X to Table 1

16

}

17

18

Procedure updateDictByField(D, Y, Subject)

19

    if(isKey(D[Subject], Y.Town/City)){

20

        if(D[Subject][Y.Town/City] < Y.Subject){

21

            D[Subject][Y.Town/City] = Y.Subject

22

        }

23

    }

24

    else{

25

        D[Subject][Y.Town/City] = Y.Subject

26

    }

27

    return(D)

28

End updateDictByField

29

30

Procedure eligible(D, X)

31

    SubList = ["Mathematics", "Physics", "Chemistry"], C = 0

32

    foreach Subject in SubList{

33

        if(D[Subject][X.Town/City] == X.Subject){

34

            C = C + 1

35

        }

36

    }

37

    return(C)

38

End eligible

Your Answer: 10

Status: Yes, the answer is correct. Score: 6

Accepted Answers:

(Type: Numeric) 10


Question 4

The following pseudocode is executed using the “Shopping Bills” dataset. At the end of the execution, the variable D captures the following information: for each customer Z, D[Z] [“Shop”] stores the shops visited by Z, and D[Z] [“Category”] stores the categories of the items purchased by Z. But the pseudocode may have mistakes. Identify all such mistakes (if any). It is a Multiple Select Question (MSQ).

xxxxxxxxxx

1

D = {}

2

while(Pile 1 has more cards){

3

    Read the top card X in Pile 1

4

    D = updateDictionary(D, X)

5

    Move X to Pile 2

6

}

7

​

8

Procedure updateDictionary(D, Y)

9

    if(not isKey(D, Y.CustomerName)){

10

        D[Y.CustomerName] = {"Shop": [], "Category": []}

11

    }

12

    D[Y.CustomerName]["Shop"][Y.ShopName] = True

13

    foreach A in Y.ItemList{

14

        D[Y.CustomerName]["Shop"][A.Category] = True

15

    }

16

    return(D)

17

End updateDictionary
  • Error in Line 1
  • Error in Line 10
  • Error in Line 13
  • Error in Line 14
  • Error in Line 16
  • No error

Accepted Answers:

  • Error in Line 10
  • Error in Line 14

Question 5

Choose the correct code fragment to complete the pseudocode.

  • xxxxxxxxxx 1 D = {} 2 foreach A in X.TrainList{ 3 foreach B in A.Days{ 4 D[B] = 1 5 } 6 } 7 ​
  • xxxxxxxxxx 1 D = {"M": 0, "Tu": 0, "W": 0, "Th": 0, "F": 0, "Sa": 0, "Su": 0} 2 foreach A in X.TrainList{ 3 foreach B in A.Days{ 4 D[B] = 1 5 } 6 }
  • xxxxxxxxxx 1 D = {} 2 foreach A in X.TrainList{ 3 foreach B in A.Days{ 4 D[B] = D[B] + 1 5 } 6 }
  • xxxxxxxxxx 1 D = {"M": 0, "Tu": 0, "W": 0, "Th": 0, "F": 0, "Sa": 0, "Su": 0} 2 foreach A in X.TrainList{ 3 foreach B in A.Days{ 4 D[B] = D[B] + 1 5 } 6 }

Status: Yes, the answer is correct. Score: 4

Accepted Answers:

  • D = {"M": 0, "Tu": 0, "W": 0, "Th": 0, "F": 0, "Sa": 0, "Su": 0} foreach A in X.TrainList{ foreach B in A.Days{ D[B] = D[B] + 1 } }

Question 6

The following pseudocode is executed using the “station wise” cards of the “Train” dataset. Consider the dictionary STN computed in the previous question. Choose the correct statement(s) from the options based on the pseudocode. It is a Multiple Select Question (MSQ).

xxxxxxxxxx

1

Z = {}, D = {}

2

foreach A in keys(STN){

3

    C = 0, Y = 0

4

    D = STN[A]

5

    foreach B in keys(D){

6

        if(Y == D[B]){

7

            C = C + 1

8

        }

9

        if(Y < D[B]){

10

            C = 1

11

            Y = D[B]

12

        }

13

    }

14

    if(not isKey(Z, C)){

15

        Z[C] = 0

16

    }

17

    Z[C] = Z[C] + 1

18

}

19

​
  • Keys of the dictionary Z is integer
  • There can be a value C such that Z[C] is zero
  • All values of the dictionary Z are non-zero
  • The number of keys in Z is 8

Status: Yes, the answer is correct. Score: 3

Accepted Answers:

  • Keys of the dictionary Z is integer
  • All values of the dictionary Z are non-zero

Question 7

Consider the dictionary STN computed in the previous question. Choose the correct pseudocode to compute the number of stations which have trains passing through all days of a week.

  • xxxxxxxxxx 1 Z = 0 2 foreach A in keys(STN){ 3 foreach B in keys(STN[A]){ 4 if(STN[A][B] < 1){ 5 C = False 6 } 7 } 8 if(C){ 9 Z = Z + 1 10 } 11 }
  • xxxxxxxxxx 1 Z = 0 2 foreach A in keys(STN){ 3 C = True 4 foreach B in keys(STN[A]){ 5 if(STN[A][B] < 1){ 6 C = False 7 } 8 } 9 if(C){ 10 Z = Z + 1 11 } 12 } 13 ​
  • xxxxxxxxxx 1 Z = 0 2 foreach A in keys(STN){ 3 C = True 4 foreach B in keys(STN[A]){ 5 if(STN[A][B] < 1){ 6 C = False 7 } 8 else{ 9 C = True 10 } 11 } 12 if(C){ 13 Z = Z + 1 14 } 15 } 16 ​
  • xxxxxxxxxx 1 Z = 0 2 foreach A in keys(STN){ 3 C = False 4 foreach B in keys(STN[A]){ 5 if(STN[A][B] < 1){ 6 C = True 7 } 8 } 9 if(C){ 10 Z = Z + 1 11 } 12 }

Status: Yes, the answer is correct. Score: 4

Accepted Answers:

  • Z = 0 foreach A in keys(STN){ C = True foreach B in keys(STN[A]){ if(STN[A][B] < 1){ C = False } } if(C){ Z = Z + 1 } }

Question 8

What will D represent at the end of the execution?

  • Frequency count of each alphabet in the table
  • Frequency count of each word in the table
  • Most frequent alphabet in the table
  • Frequency count of each alphabet in each part of speech

Status: Yes, the answer is correct. Score: 3

Accepted Answers:

  • Frequency count of each alphabet in the table

Question 9

Consider the dictionary D and the procedure updateDictionary() in the previous question. Let POS be a list that contains all part of speeches. Assume that given a dictionary D, there exists a procedure max such that max(D) returns a list of keys which are mapped to the maximum value. Choose the correct statement(s) from the options based on the following pseudocode. It is a Multiple Select Question (MSQ).

xxxxxxxxxx 1 C = {"Overall": max(D)} 2 foreach A in POS{ 3 Move all rows to Table 1 4 B = {} 5 while (Table 1 has more rows){ 6 Read the first row X in Table 1 7 if(X.PartOfSpeech == A){ 8 B = updateDictionary(B, X) 9 } 10 Move X to Table 2 11 } 12 C[A] = max(B) 13 } 14 ​

  • length(keys(C)) is same as the number of different part of speeches in the input dataset
  • C captures the list of most frequent alphabet occurred overall in the dataset as well as for each part of speech
  • C captures the most frequent alphabet occurred overall in the dataset as well as for each part of speech
  • length(keys(C)) is one more than the number of different part of speeches in the dataset

Status: Yes, the answer is correct. Score: 4

Accepted Answers:

  • C captures the list of most frequent alphabet occurred overall in the dataset as well as for each part of speech
  • length(keys(C)) is one more than the number of different part of speeches in the dataset

Question 10

The following pseudocode is executed using the “Shopping bills” dataset. What will D represent at the end of the execution?

xxxxxxxxxx

1

D = {}

2

while(Pile 1 has more cards){

3

    Read the top card X in Pile 1

4

    D = updateDictionary(D, X)

5

    Move X to Pile 2

6

}

7

8

Procedure updateDictionary(D, Y)

9

    foreach A in Y.ItemList{

10

        C = A.ItemName

11

        if(isKey(D, C)){

12

            if(isKey(D[C], Y.ShopName)){

13

                if(D[C][Y.ShopName]["Price"] != A.Price){

14

                    D[C][Y.ShopName]["Flag"] = True

15

                }

16

            }

17

            else{

18

                D[C][Y.ShopName] = {"Price": A.Price, "Flag" : False}

19

            }

20

        }

21

        else{

22

            D[C] = {}

23

            D[C][Y.ShopName] = {"Price": A.Price, "Flag" : False}

24

        }

25

    }

26

    return (D)

27

End updateDictionary
  • For an item C, and a shop S, D[C] [S] [“Flag”] is set to True if and only if the item is sold for a constant price
  • For an item C, and a shop S, D[C] [S] [“Flag”] is set to True if and only if the item is billed in more than one bill
  • For an item C, and a shop S, D[C] [S] [“Flag”] is set to True if and only if the item is sold for variable price
  • For an item C, and a shop S, D[C] [S] [“Flag”] is set to True if and only if the item is billed exactly one bill

Status: Yes, the answer is correct. Score: 4

Accepted Answers:

  • For an item C, and a shop S, D[C] [S] [“Flag”] is set to True if and only if the item is sold for variable price