CA201 Assignment 02
CA201 Assignment 02
Instructions
Maximum points 33. Bonus points 07.
Write your answers in a text file. Name of file should be rollNumber.txt. Once you done writing all your responses
submit this file on moodle.
If you submit your work before 1 pm 7 May 2022, you will get bonus 7 points. This bonus points will be given
only if you have sent some logical responses.
Final deadline 11.59 pm 7 May 2022
There will be bonus points if you can also provide rough code along with some sample test cases for your solutions.
Problem 01
We need to design a part of audio player. The audio player gets song data in form of packets. To enhance the performace
we want to buffer/cache the packets in advance. So the reciever gets one packet at a time from source and puts it in the
cache. And player take one packet at a time from cache and converts it to the audio. Cache is of constant size so receiver
cant put any further packets if cache is full. As soon as a packet is read that location becomes empty.
1. We need to design this cache. Define interface, methods and data structure which can be used here. If logic and
reasoning is missing, you will not get any points. (5 points)
2. We want to additional feature of playback by 10 seconds. Basically this feature takes audio 10 seconds back from
current position(minimum 10 seconds). Each packet contains 100 milisenconds to 5 seonds of audio data. What
additional methods and changes will be required for this feature. If logic and reasoning is missing, you will not get
any points. (8 points)
Problem 02
We need to design a task executor. A task can be divided into multiple sub tasks. Each sub task can also be further be
divided into multiple smaller tasks. Suppose we represent this task data as a string t1 (t2 (t4() t5 (t6() t7())) t3()),
this represnt t1 has 2 tasks t2 and t3. t2 has t4 and t5. t5 has 2 sub tasks t6 and t7. t4, t6, t7 and t3 does not have any
sub tasks. Now suppose our task executor takes this string and performs the task. Remember a task is completed only if
all inner sub tasks are done. As per given example, t5 is considered as completed only if t6 and t7 are done.
1. Describe the interface, methods and data structures which can be used here. If logic and reasoning is missing, you
will not get any points. (7 points)
2. Cost of task depends on depth of the subtasks. Eg for above given example maximum depth is 3 (t1 → t2 → t5 → t6).
Describe algorithm which takes the task string and will compute depth of the task. (5 points)
If logic and reasoning is missing, you will not get any points. Provide complexity of each method.
1
Problem 03
We are using following structure to store words of a document.
s t r u c t Word{
c h a r *w ; // word s t r i n g
int p; // page number
i n t cnt ; // count o f word ’w’ a t page number p
};
Suppose we have array of Word. We pass this array to some sorting alogrithm twice. First we sort by word string then
we sort by page number p. We cant see code of this sorting algorithm.
Describe a strategy to check if the sorting algorithm is stable or not. You are allowed to change the structure. Make sure
you describe all steps of your strategy. Bonus points if your algorithm does not make any changes to struture and takes
O(n) time. (8 points)