23CSE006 CPS MID Set 2
23CSE006 CPS MID Set 2
Roll No.: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Amrita Vishwa Vidyapeetham
Amrita School of Computing, Coimbatore
B.Tech. Mid-term Examinations – Oct 2023
First Semester
Computer Science and Engineering
23CSE101 Computational Problem Solving
Part A 30 Marks
1. Priya and Vidhya are planning to design a vacuum cleaning robot for cleaning the room without
any human intervention. The primary functionality is to accurately map the coordinates of the
room without any collisions and store it. As a trial-and-error case, they have organized the room to
be in the form of plane as shown in the Figure 1. They placed the robot in the plane origin (0,0).
The robot can move in the following directions in the plane as UP(U), DOWN(D), LEFT(L) and
RIGHT(R) with a given number of steps. [15 marks] [CO2] [BTL3]
Figure 1
Now, the initial task is to trace the movement of the robot, compute the distance travelled by each
movement (distance between previous and current coordinate positions using the formula
(Manhattan distance metric)) it takes and summing them up to get the total distance.
Page 1 of 5
Input to the python program is given in the form of direction and steps it takes to move. It can take
any form as shown in the sample input below. For Example: UP 3 or U 3 - both are valid inputs
and will move the robot UPWARD 3 steps. The input stops when the user presses enter key twice.
Use proper data structure to store the co-ordinate points. Display each X- and Y- coordinate
positions from the initial point to the final Co-ordinate where the robot is in as two separate lists
and the total distance the robot has travelled.
Sample Input:
UP 5 or U 5
RIGHT 3 or R 3
UP 3 or U 3
LEFT 1 or L 1
Sample Output:
[0, 0, 3, 3, 2] [0, 5, 5, 8, 8]
12 (# 5+3+3+1)
2. Read the register number (3-digit integer values) and GPA (a real number between 0.0 and 10.0)
for N students. Number of students (N) is accepted as an input from the user. Construct a
Dictionary using register number as Key and GPA as the value. The summer internship eligibility
criterion for a student is a GPA of more than 7. Write a menu-driven python program that does
the following based on the option selected. [15 marks] [CO2] [BTL3]
1. Print the contents of the dictionary.
2. Display the count of students eligible for summer internships.
3. Print the average GPA of students who are not eligible for internship.
4. Out of all students who are not eligible for internship, display the student register
number who has the least difference between current GPA and eligibility cut-off value 7.
5. Out of the Internship-eligible students, display the student register number who scored
the highest GPA.
Input Specification
• Read the number of students N
• It is followed by reading each student’s register number and GPA, for N students.
• Last input is the choice of operation to be performed.
Output Specification
• Print the output as per the choice opted for.
Page 2 of 5
Sample Input
3
101
6
203
6.5
405
8
1
Sample Output
{101: 6.0, 203: 6.5, 405: 8.0}
[Expected results for the same input for other possible options
# for option 2
1 (#only the student 405 is eligible for the internship. Hence, the count is 1)
# for option 3
6.25 (#Average GPA of 101 and 203)
# for option 4
203 (#Student with least difference in his/her GPA against the summer internship
criterion of 7)
# for option 5
405 (# Register number of the student with highest GPA out of internship-eligible
students)
Part B 20 Marks
3. Consider the algorithm named FindMax detailed below. [5 marks] [CO01] [BTL2]
Algorithm: FindMax
Input: A list of integers L
Output: The maximum value in the list
Page 3 of 5
a. Using the step number provided, identify and list which steps of the algorithm represent
the components ‘Initialization’, ‘Conditional Statement’, and ‘Termination’. (2 Marks)
b. If the algorithm is to be modified to find the minimum value, which step must be re-
written? (1 mark)
c. Consider a scenario where the input list L is empty. How would the algorithm behave,
and what would be the output? Explain whether this behaviour aligns with the expected
properties of the algorithm. (2 Marks)
4. Dhruv is playing Mastermind on his computer: The computer makes up a password made up of four
distinct digits. The player can submit several guesses of this password. Each time, the computer
responds with cues and hints like the number of correct digits, which appear both in the guess and in
the password. Also, it tells the player whether they placed these digits in the right positions. Dhruv
made the following five guesses (columns 1-4 show the four-digit password guessed). Column 5
shows the responses given by the computer. From the responses given by the computer, can you
guess the password correctly? [5 marks] [CO01] [BTL3]
5. Write a Python program to count the occurrences of each letter in a name inputted by the user and
store them in a dictionary in a manner that the alphabets are keys, and their frequencies are values.
[5 marks] [CO03] [BTL3]
6. Trace the following python program. Use the following trace table for your tracing. [5 marks]
[CO04] [BTL4]
num = 1729
sum = 0
while num > 0:
digit = num % 10
sum = sum + digit
num = int(num / 10)
n sum digit
Page 4 of 5
*******
Page 5 of 5