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

CS2201: : End Sem (Group A + B)

Duration: 2 hours Total marks: 40

General Instructions

• All programs should be compatible with Python 3.


• There will be a plagiarism check. The suspected copies will attract a deduction of
marks for the problem irrespective of who is the original author of the code. Copying
from internet will also be considered as plagiarism. However, you may reuse the codes
shared by the instructor.

• Late submissions will attract marks deduction.


• You are advised to compile the code before submitting them to WeLearn. If a code
does not compile at our end, marks will be deducted for the problem.
• Each program should follow a strict naming convention: QNo.py (e.g. Q1.py, Q2a.py
etc.). Programs not adhering to the convention will not be considered for evaluation.
• All codes (.py files) should be submitted in a single zipped folder to WeLearn.
• You should put appropriate comments in the code without which marks will be de-
ducted.

Instructions on the questions


• Questions 1, 2 and 3 are compulsory. In addition, attempt any one of questions 4 and
5.
3
• If you attempt question 4, there is a bonus of up to 2 marks if you get at least 7 out
of 10 to award you the full marks. E.g. if you get 7 (or more but not the full marks),
you will be awarded the full marks (10).

1. (Marks: 10) Consider the yearwise Sensex Annual Returns of the Bombay Stock Exchange from 2014
to 2022 as shown in Table 1.

Year (x) 2014 2016 2018 2020 2022


Sensex Annual Returns (in Percentage) (y) 19 -9 11 -24 18

Table 1: Table for Q3

Implement a suitable Interpolation formula to find the Sensex Annual Returns for year 2015.
2. (Marks: 10) A pack of assorted chocolates contains some dark flavored toffees, some white flavored
toffees and some hazelnut flavored toffees. If you multiply the number of dark flavored toffees by 3,
deduct twice the number of white flavored toffees from it and add the number of hazelnut flavored
toffees to it, you get 17. The sum of the number of dark, white and hazelnut toffees is 16. Finally, if you
consider the number of dark flavored toffees, deduct the number of white flavored toffees from it and
add the number of hazelnut flavored toffees to it, you get 6.
Express the above information in terms of numbers of the three types of toffees as the variables and
solve the system of equations using np.linalg.det() to find the number of each type of toffee.
3. (Marks: 10) A man Ravi is imprisoned in a castle. Every day he wakes up and tosses a fair coin and
decides on Heads that he should try to escape, or else he waits for the day. In case he decides to try
an escape, he walks to a point where there are two routes leading to two gates. There he tosses a fair
coin again: on Heads he chooses Gate 1, on Tails chooses Gate 2. At Gate 1, there is a guard who asks
4 questions in order with increasing difficulty level such that the chances for Ravi to answer them are
95%, 90%, 85% and 80% (in this order). At Gate 2, there is another guard who asks 2 questions in
order with increasing difficulty level such that the chances for Ravi to answer them are 70% and 50%
(in this order). Ravi can escape if he is able to answer ALL of the questions for the chosen gate. Use
random() function of python module random to simulate the coin tossing events and uniform() function
of the same module to simulate the question-answering events. Print a message at every stage of decision
making. A sequence of events when Ravi chooses to go for an escape, chooses Gate 1 and successfully
escapes is:
Let’s try today!
Gate 1 chosen!
Answer 0 correct!
Answer 1 correct!
Answer 2 correct!
Answer 3 correct!
Congrats!
4. [TRY IF YOU ARE BRAVE!!]
Consider a query auto-completion system in a search engine. Construct a question bank containing the
list of all the previously searched queries. The question bank may contain queries like “how to dance”,
“how to make coffee”, “how to write c program”, “how to cook”, “how to cook pasta”, “how to write a
formal letter” etc.
(a) (Marks: 4) Take an incomplete query (e.g. “how to write”) as input from the user and print the
queries as suggestion that exactly match (in sequence) the input query. For the example input, the
automatically suggested complete queries should be “how to write c program” and “how to write a
formal letter”.
(b) (Marks: 6) Modify the above system to suggest complete queries even if there is no exact match.
However, only the best suggestions (those with the maximum match) should be displayed. That is,
for the input query “how do I cook”, the suggestions should be:
how to cook
how to cook pasta
5. [TRY IF YOU LIKE TO PLAY SAFE !!]
Consider the Minimum CGPA (for PhD admission) and QS World University Ranking of some universi-
ties/institutes shown in Table 2. The target is to automatically suggest the suitable universities/institutes
for a given student profile.
(a) (Marks: 5) Assume the CGPA-Ranking pairs as points on a 2-dimensional Euclidean space and
on this construct your dataset for clustering. Also plot these points using scatter plot of Matplotlib.
Apply the elbow method of K-means clustering to chose the appropriate value of K (also trust
your eyes!) and using this value finally cluster the data using K-means algorithm implemented in
sklearn into different groups. Plot the output of the elbow method and the final clusters of these
groups using scatter plot of Matplotlib.
(b) (Marks: 5) Now take a Student Name and her/his total Master’s CGPA and QS ranking of the
university/institute where she/he obtained her/his Master’s degree, as input from the user. The
scheme for the recommendation of the suitable universities/institutes to the student works as follows:
the student’s (CGPA, QS ranking) is compared with the points in each cluster; for each cluster the
farthest data point from student’s (CGPA, QS ranking) is identified; among these cluster-wise
farthest data points, the closest one is picked and the cluster of this picked data point gives the
set of suitable universities/institutes for the student. Note that, for K = n, n is a positive integer,

Page 2
University/Institute Name Minimum CGPA (out of 10) QS Ranking
Harvard 9.4 5
MIT 8.5 1
Stanford 8.5 3
Princeton 9.7 16
Ghent 6.0 390
Adeleide 6.5 109
Liverpool 7.5 190
Nagoya 7.5 112
Peking 8.75 12
NTU 8.5 19
Griffith 6.2 300
Stuttgart 6.5 355

Table 2: Table for Q5

the
p clusters are labelled as [0, 1, 2, ..., n-1]) and for two points (x1 , y1 ) and (x2 , y2 ), distance is
(x1 − x2 )2 + (y1 − y2 )2 . Also plot the clusters with the student (in a different colour) on a scatter
plot of Matplotlib. E.g. if the student’s CGPA and QS ranking respectively are 8.5 and 52, then
the recommended universities/institutes will be the likes of Harvard, MIT, Stanford etc.

Page 3

You might also like