COL100 A3 Questions
COL100 A3 Questions
2. Analysis of correctness and efficiency must be carried out for all nontrivial helper func-
tions as well as for the main function. Any function that performs recursion counts as
nontrivial, as does any function that calls a nontrivial function.
4. For the programming component of each question, the name and the type of the main
function must be exactly as specified in the question. You can take help of the test cases
provided to validate your code
5. Any function that has integer input and output must not perform any intermediate
computation using reals.
1
(b) Convert a number in list format into its equivalent integer. (If the number in list
format exceeds 109 , then the function should just return 109 ).
(d) Compare two numbers in list format. The algorithm should return True if 𝑙1 ≤ 𝑙2
and False otherwise.
2. Prove the correctness of your algorithms and analyze their time and space complexities.
(2 marks)
Bonus: Design an algorithm for multiplication of two numbers in list format and implement
your algorithm in the form of a function multiplyLgint : int list ∗ int list → int list.
2 Quarterly Performance
You are given a list of tuples of employees in a start-up, where each tuple contains an employee’s
performance points for each quarter in the last year and their current salary (𝑠𝑎𝑙𝑎𝑟𝑦 = 100 ∗ 𝑖
for some 𝑖 ∈ N).
You are expected to find the average performance of each quarter for all the employees and if
an employee’s performance is above the average performance of that quarter provide them
with a salary hike of 1% increment on base salary when at least 10% gain compared to average
and in increments of 1% for every additional 10% difference between their points and average.
For example, if their points are 42 and if the average for that quarter is
The total salary hike for an employee will be done accordingly using all quarters and output
the resultant salaries of all the employees.
For example, if the input is [(10, 20, 30, 40, 100000), (30, 30, 20, 50, 150000), (60, 10, 10, 50,
200000)], the output would be [105000, 157500, 216000]. Finally, calculate the overall percentage
raise in salary budget the start-up has to handle solely considering salary hike. which would
be 0.0633… for the above example
2
1. Design an algorithm to apply the above logic on a list of employees and argue on its
correctness. You should use higher order list functions like map, filter and foldl/r as to
the extent possible. (3 marks)
3 Lexicographic Permutations
Lexicographic ordering is what you may have already noticed in the ordering of words according
to alphabet in the dictionary.
More formally, Given two lists [𝑎 1, 𝑏 1 ] and [𝑎 2, 𝑏 2 ], they are said to be [𝑎 1, 𝑏𝑙 ] < [𝑎 2, 𝑏 2 ] in a
lexicographical order iff either 𝑎 1 < 𝑎 2 or 𝑎 1 = 𝑎 2 and 𝑏 1 < 𝑏 2 . This can be extended to lists of
characters of arbitrary length by recursively applying this definition.
For example, [𝑎, 𝑏, 𝑐] < [𝑎, 𝑐, 𝑏] < [𝑐, 𝑎, 𝑏] if we are to take the English alphabet order for the
lists of characters. For example for
1. Design an algorithm which enumerates all permutations of the given list of distinct
characters in lexicographic order and prove its correctness. For example for input [a,b,c]
the output will be [[a,b,c],[a,c,b],[b,a,c],[b,c,a],[c,a,b],[c,b,a]]. (3 marks).
1. One file should be a PDF file containing all your written work, i.e. mathematical definitions
of algorithms, correctness and efficiency analysis, etc. This can be handwritten with pen
and paper and then scanned with your mobile, or it can be typed on your device using
MS Word or LaTeX or any other software. The only requirement is that it should be
clearly legible.
3
2. The other file should be an SML file containing all your code. Put your solutions to all four
programming problems into a single file, along with any helper functions they require.
We should be able to run any of the four required functions by typing in a function call
at the bottom of the file.
The filenames of your submitted files should be exactly the same as your entry number. For exam-
ple, if your entry number is 2017CS10389, you should name your SML file as 2017CS10389.sml
and your PDF file as 2017CS10389.pdf. Your submission should consist of only these two files,
uploaded individually. There should be no sub-folders or zip files in the submission on Moodle.
Please ask any queries related to the assignment on the COL100 Piazza page (https://piazza.
com/iit_delhi/fall2020/col100).