Uploaded by Siddharth Kumar

List21

advertisement
The marks will be provided on the basis of:
1. Originality of code
2. Code Structure
3. Readability
4. Functionality implemented
5. Robustness
6. Scalability
7. CODE COMPLEXITY
Note: Whatever data structure you use, provide the complete implementation of it.
Set 1
A and B are playing a game. In this game, both of them are initially provided with a list of
numbers.
Now, they both have a different strategy to play the game.
A picks the element from start of his list.
B picks from the end of his list.
You need to generate the result in form of an output list.
Method to be followed at each step to build the output list is:
1. If the number picked by A is bigger than B then this step's output is 1. B removes the
number that was picked from his list.
2. If the number picked by A is smaller than B then this step's output is 2. A removes the
number that was picked from his list.
3. If both have the same number then this step's output is 0. Both A and B remove the
number that was picked from their list.
This game ends when at least one of them has no more elements to be picked i.e. when the list gets
empty. Output the built output list. Analyse the time complexity of your algorithm.
Set 2
John has a string of lowercase characters in range ascii[‘a’..’z’]. He wants to reduce the string to its
shortest length by doing a series of operations. In each operation he selects a pair of adjacent
lowercase letters that match, andhe deletes them. For instance, the string aab could be shortened to
b in one operation.
John’s task is to delete as many characters as possible using this method and print the resulting
string. If the final string is empty, print "Empty String" without quotes.
characters can be deleted only if they form a pair and are same(i.e from aaa we can only delete 2 a's
and will be left with a single a).
Use appropriate data structure and analyse the time complexity of your algorithm.
Set 3
X wants to kill the maximum possible number of enemies. He can kill every person standing at
leftmost of each level of the BST and cannot see the rest.
Before starting shooting them, he wants to know how many persons he can kill. Find out the
maximum number of people he can kill from that location. Analyse the time complexity of your
algorithm.
Set 4
Implement priority scheduling of processes in a system using a priority queue implemented through
heap. The code should handle arrival, wait, execution and termination of processes.
Set 5
A magician showed a trick to store 30 numbers in the range [1000,9999] in a crate of size 20, with
the possibility of more than one number to be placed at the same position. The magician decides
where to put the number based on the middle two digits of the number. When asked to pick up any
number, he goes directly to that position. Implement the technique and find out where the following
numbers would be stored: 1206, 7822, 6467, 8990, 1211, 4444, 6701, 5468, 7345 and 8210.
Analyse the time complexity of your algorithm.
Set 6
Implement insert,delete and search operations in an AVL Tree. Analyse the time complexities of all
functions.
Set 7
A shop owner has n products that he sells. He has limited storage space so he has reserved fixed
storage capacity for each product i.e, c1,c2,c3...cn. Whenever he buys a product, he places it on top
of its other pieces and whenever he sells a product he removes a piece from the top. Implement the
buying and selling of products in this manner using a single stack with multiple tops as the data
structure. Analyse the time complexity of the algorithm.
Download