0% found this document useful (0 votes)
8 views2 pages

CS2006

The document outlines the structure of an end-term examination for the Design and Analysis of Algorithms course at the National Institute of Technology, Rourkela. It includes various algorithm-related questions covering topics such as divide-and-conquer, dynamic programming, greedy algorithms, and backtracking, with specific tasks like finding maximum/minimum elements in arrays, implementing sorting algorithms, and solving the knapsack problem. Each question is designed to assess students' understanding of algorithm design, analysis, and application.

Uploaded by

srk712906
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

CS2006

The document outlines the structure of an end-term examination for the Design and Analysis of Algorithms course at the National Institute of Technology, Rourkela. It includes various algorithm-related questions covering topics such as divide-and-conquer, dynamic programming, greedy algorithms, and backtracking, with specific tasks like finding maximum/minimum elements in arrays, implementing sorting algorithms, and solving the knapsack problem. Each question is designed to assess students' understanding of algorithm design, analysis, and application.

Uploaded by

srk712906
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

NATIONAL INSTITUTE OF TECHNOLOGY, ROURKELA

END-TERM EXAMINATION, SPRING SEMESTER- 2024


ANSWER ANY FIVE QUESTIONS
All Parts of a question should be answered at one place.
SUBJECT: Design and Analysis of Algorithm Subject Code: CS2006
FULL MARKS : 50 Duration of Examination: 3 Hours

1[a] Given an array of n integers, describe a divide-and-conquer algorithm to find the maximum
and minimum elements in the array. You should aim to minimize the number of
comparisons. Provide the pseudo-code for the algorithm. Calculate the total number of
comparisons made by your algorithm.

1[b] QuickSort algorithm, Explain the partition process with the help of a diagram. Provide an
algorithm for a randomized version of QuickSort. Discuss the worst-case and average-case
time complexities of QuickSort.
[5+5]
2[a] You are given an array of integers where each number appears three times except for one
which appears exactly once. Write an algorithm to find the single non-repeated integer
without using extra space for storing counts. Provide a clear algorithmic description using
bitwise operations. Analyze the time complexity of your algorithm.

2[b] Bellman-Ford algorithm is used for finding the shortest path from a single source in a
weighted graph, which may have negative weight edges. Write the pseudo-code for the
Bellman-Ford algorithm. Prove its time complexity and discuss under what condition this
algorithm fails.
[5+5]
3[a] You are to design a greedy algorithm for the coin change problem, where you are given
denominations that are powers of c (e.g., 1, c, c², ... ck) and you need to make change for n
using the fewest coins possible. Provide the greedy algorithm's pseudo-code. Prove why
this greedy solution is optimal for denominations of powers of c.

3[b] You are required to construct a minimum spanning tree (MST) from a connected,
undirected graph with n vertices and m edges using Prim’s algorithm. Describe Prim’s
algorithm. Provide the pseudo-code for Prim’s algorithm, including the data structures
used. How the use of data structures affects the complexity of Prim’s algorithm?
[5+5]
4[a] Define the Longest Common Subsequence (LCS) Problem. Given the sequences X =
"ABCBDAB" and Y = "BDCAB", compute the length of the LCS. Show your work. Write an
algorithm to print the longest common subsequence. The standard dynamic programming
solution for the LCS problem uses a table with dimensions based on the lengths of the two
sequences. Discuss how you can reduce the space complexity of the LCS solution.

4[b] Suppose a[1:m] and b[1:n] both contain sorted elements in non-decreasing order. Write
an algorithm “Merge” that merges these items into c[1:m+n] single sorted sequences in O
(n) time. Is it possible to design an efficient algorithm in comparison to “Merge”?

[5+5]

Page 1 of 2
5[a] You are given an array p[], which represents the chain of matrices such that the ith matrix Ai
has dimension pi-1 × pi. Write an algorithm that returns the minimum number of
multiplications needed to multiply the chain.
5[b] Write TVS algorithm for a directed binary tree with weighted edge. Use the algorithm for
the given network and a loss tolerance level  =8, determine the optimal placement of
boosters in the network represented as follows, If tree[i] has a tree node, the weight of the
incoming edge from its parent is stored in weight[i].
Tree[i] 1 2 3 0 4 5 6 0 0 7 8 0 0 9 10
Weight[i] 0 4 2 0 2 1 3 0 0 1 4 30 0 2
[5+5]
6[a] What are the main steps of a backtracking algorithm? What is dead-end in a backtracking?
State the different constraints to be satisfied while solving a optimization problem using
backtracking? Discuss how BACKTRACKING is used to solve 4-queens problem where
solution space is organized as a tree.

6[b] Discuss the structure of knapsack problem? Explain how this problem can be solved using
Dynamic programming. Find an optimal solution the knapsack problem with instance n =7,
m=15 with ( P1, P2, .., P7) = (10, 5, 15, 7, 6, 18, 3) and (w1, w2, … , w7) = (2, 3, 5, 7, 1, 4, 1).
[5+5]
7[a] Explain the generic method for branch and bound algorithms. How does branch and bound
method solve the 0/1 Knapsack problem? Use the following instance n = 5, (p1, p2, p3, p4,
p5) = (10,15, 6, 8, 4), (w1, w2, w3, w4, w5) = (4, 6, 3, 4, 2), and m = 13 to explain branch and
bound algorithm. Will the branch and bound algorithm perform better that the dynamic
programming solution? Justify.

7[b] You are given coins of different denominations i.e. d1, d2, … dk and a total amount of
money M. Write an Algorithm to compute the number of combinations that make up that
amount. You may assume that you have an infinite number of each kind of coin.
[5+5]
[8] The All-Pairs Shortest Paths (APSP) problem is to find the shortest paths between every
pair of vertices in a given weighted graph.
[a] Suggest a dynamic programming algorithm(s) to compute the length of the shortest path
between every pair of vertices. What is the time complexity of the algorithm and how does
it affect the choice of algorithm based on graph size and type?
[b] Suggest an algorithm to compute the path between every pair of vertices.
[c] Demonstrate the working of the All-Pairs Shortest Paths algorithm for the following
directed graph represented as adjacency matrix.

1 2 3 4 5
1 0 6 8 ꝏ -4
2 5 0 ꝏ 1 7
3 3 4 0 ꝏ 8
4 2 ꝏ -5 0 ꝏ
5 ꝏ ꝏ ꝏ 3 0
[3+3+4]
--------------------------------------- Good luck ---------------------------------------

Page 2 of 2

You might also like