2021-April-MTech-DAA-Programming Assignments
2021-April-MTech-DAA-Programming Assignments
[Coin Tossing] Using simulation, show that the probability of getting HEAD by tossing a fair
coin is about 0.5. Write your observations from the simulation run.
Sample Output
Q2. [Performance Analysis of Popular Sorting Methods] Write a program to analyze and
compare the following sorting algorithms
● Bubble sort
● Selection sort
● Insertion sort
● Merge sort
● Quicksort
You must run the above algorithms on the following input data patterns
● Random data
● Reverse order data
● Highly repetitive data
● Almost sorted data
For example, if you run these sorting algorithms on the random input data, your result may look
something like this
After the simulation, justify your observations corresponding to the input patterns described
above.
Q3. [ QuickSort vs Variant of Quicksort] Compare the quicksort sort with another variant of
quicksort as follows:
Modify the quicksort algorithm to stop partitioning the list in quicksort when the size of
the (sub)list is less than or equal to 20 and sort the remaining (sub)list using INSERTIONSORT.
Your program must count the number of comparisons in both cases and plot a graph for
different input sizes. Comment upon your results.
Q4. Given a set of 𝑛 objects, each having an integer weight and profit. What is the optimal
selection of objects that maximizes the value contained in the knapsack subject to the constraint
that the total size of the objects placed in the knapsack be less than or equal to the capacity of
the knapsack. The greedy approach to this problem does not necessarily produce an optimal
solution. Write a dynamic programming algorithm to find a solution to this problem. Run this
algorithm, along with the greedy algorithm on the following dataset and compare the solution
obtained by each.
Size of knapsack = 120
Number of items in the set to choose from = 25
𝑡ℎ
Set of objects = {(𝑤𝑖, 𝑣𝑖), 𝑤ℎ𝑒𝑟𝑒 𝑤𝑖 𝑖𝑠 𝑡ℎ𝑒 𝑤𝑒𝑖𝑔ℎ𝑡 𝑎𝑛𝑑 𝑣𝑖 𝑖𝑠 𝑡ℎ𝑒 𝑣𝑎𝑙𝑢𝑒 𝑜𝑓 𝑡ℎ𝑒 𝑖 𝑜𝑏𝑗𝑒𝑐𝑡 }
=
{(15, 20), (30, 25), (5, 10), (35, 30), (40, 25), (17, 21), (12, 23), (24, 16), (9, 24), (7, 16), (28, 31), (29, 27
(16, 28), (3, 8), (6, 17), (12, 15), (5, 7), (9, 14), (14, 29), (20, 24), (14, 9), (6, 10), (2, 3), (19, 24), (20, 28)
Q5. Given a matrix chain 𝐴1, 𝐴2, ···, 𝐴𝑛 with the dimension of each of the matrices given by the
vector
𝑝 = < 12, 21, 65, 18, 24, 93, 121, 16, 41, 31, 47, 5, 47, 29, 76, 18, 72, 15 > (𝑛 = 17).
Write and run a dynamic programming approach to find the minimum number of multiplications
that are needed to multiply the 𝐴1 × 𝐴2 × ···× 𝐴17and the corresponding multiplication order.