Description
MCS-211 Solved Assignment 2025 Available
Q1: a) Design and develop an efficient algorithm to find the list of prime numbers in the range 501 to 2000. What is the complexity of this algorithm?
b) Differentiate between Cubic-time and Factorial-time algorithms. Give example of one algorithm each for these two running times.
c) Write an algorithm to multiply two square matrices of order n*n. Also explain the time complexity of this algorithm.
d) What are asymptotic bounds for analysis of efficiency of algorithms? Why are asymptotic bounds used? What are their shortcomings? Explain the Big O and Big notation with the help of a diagram. Find the Big O-notation and Θ-notation for the function:
𝑓(𝑛)= 100𝑛4 +1000𝑛3 +100000
e) Write and explain the Left to Right binary exponentiation algorithm. Demonstrate the use of this algorithm to compute the value of 329 (Show the steps of computation). Explain the worst-case complexity of this algorithm.
f) Write and explain the Bubble sort algorithm. Discuss its best and worst-case time complexity.
g) What are the uses of recurrence relations? Solve the following recurrence relations using the Master’s method
a. 𝑇(𝑛) = 4𝑇 (𝑛
4 ) + 𝑛1
b. 𝑇(𝑛) = 4𝑇 (3𝑛
4 ) + 𝑛1
Q2: a) What is an Optimisation Problem? Explain with the help of an example. When would you use a Greedy Approach to solve optimisation problem? Formulate the Task Scheduling Problem as an optimisation problem and write a greedy algorithm to solve this problem. Also, solve the following fractional Knapsack problem usinggreedy approach. Show all the steps. Suppose there is a knapsack of capacity 20 Kg and the following 6 items are to packed in it. The weight and profit of the items are as under:
(p1, p2,…, p6) = (30,16,18,20,10, 7)
(w1, w2,…, w6) = ( 5, 4, 6, 4, 5, 7)
Select a subset of the items that maximises the profit while keeping the total weight below or equal to the given capacity.
b) Assuming that data to be transmitted consists of only characters ‘a’ to ‘g’, design the Huffman code for the following frequencies of character data. Show all the steps of building a huffman tree. Also, show how a coded sequence using Huffman code can be decoded.
a:5, b:25, c:10, d:15, e:8, f:7, g:30
c) Explain the Merge procedure of the Merge Sort algorithm. Demonstrate the use of recursive Merge sort algorithm for sorting the following data of size 8: [19, 18, 16,
12, 11, 10, 9, 8]. Compute the complexity of Merge Sort algorithm.
d) Explain the divide and conquer approach of multiplying two large integers.
Compute the time complexity of this approach. Also, explain the binary search algorithm and find its time complexity.
e) Explain the Topological sorting with the help of an example. Also, explain the algorithm of finding strongly connected components in a directed Graph.
Q3: Consider the following Graph: Figure 1: A sample weighted Graph
a) Write the Prim’s algorithm to find the minimum cost spanning tree of a graph.Also, find the time complexity of Prim’s algorithm. Demonstrate the use of Kruskal’s algorithm and Prim’s algorithm to find the minimum cost spanning tree for the Graph given in Figure 1. Show all the steps.
b) Write the Dijkstra’s shortest path algorithm. Also, find the time complexity of this shortest path algorithm. Find the shortest paths from the vertex ‘A’ using Dijkstra’s shortest path algorithm for the graph given in Figure 1. Show all the steps of computation.
c) Explain the algorithm to find the optimal Binary Search Tree. Demonstrate this algorithm to find the Optimal Binary Search Tree for the following probability data (where pi represents the probability that the search will be for the key node ki,whereas qi represents that the search is for dummy node di. Make suitable
assumptions, if any)
i 0 1 2 3 4
pi 0.10 0.15 0.20 0.10
qi 0.05 0.10 0.10 0.10 0.10
10
4
15
16
7
8
5
20
6
A
B C
E
D
F
G
5
d) Given the following sequence of chain multiplication of the matrices. Find the optimal way of multiplying these matrices:
Matrix Dimension
A1 10 × 15
A2 15 × 5
A3 5 × 20
A4 20 × 10
e) Explain the Rabin Karp algorithm for string matching with the help of an example.Find the time complexity of this algorithm.
Q4: a) Explain the term Decision problem with the help of an example. Define the following problems and identify if they are decision problem or optimisation problem? Give reasons in support of your answer.
(i) Travelling Salesman Problem
(ii) Graph Colouring Problem
(iii) 0-1 Knapsack Problem
b) What are P and NP class of Problems? Explain each class with the help of at least c) Define the NP-Hard and NP-Complete problem. How are they different from each other. Explain the use of polynomial time reduction with the help of an example.
d) Define the following Problems:
(i) SAT Problem
(ii) Clique problem
(iii) Hamiltonian Cycle Problem
(iv) Subset Sum Problem
Reviews
There are no reviews yet.