JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD

JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD B. Tech III DESIGN AND ANALYSIS OF ALGORITHMS Previous Question Paper (September - 2021 - R16)

B. Tech | III | I | R16 | September - 2021

Answer PaperPaper Code: 135AFMaximum Marks: 75Time: 3 hours

Answer any five questions

All questions carry equal marks

Main

1

Design an algorithm to sort the given list of elements using Quick Sort incorporating divide and conquer technique. Sort the following list using the same and compute its best case time efficiency: 4, 2, 0, 8, 7, 1, 3, 6.

15 marks

Answer

Quick Sort is a divide and conquer algorithm that picks an element as a pivot and partitions the array around the chosen pivot. The process involves three steps: Divide by choosing a pivot and partitioning the array into two sub-arrays such that elements in the left sub-array are less than or equal to the pivot and elements in the right are greater; Conquer by recursively applying the algorithm to the sub-arrays; and Combine, which is trivial as the sub-arrays are sorted in place.

Algorithm:

  1. Choose an element as pivot (e.g., the last element).
  2. Partition the array: maintain an index i, iterate through the array, and swap elements smaller than the pivot to the front.
  3. Place the pivot in its correct sorted position.
  4. Recursively sort the left and right partitions.

Sorting the list [4, 2, 0, 8, 7, 1, 3, 6]:

  1. Initial: [4, 2, 0, 8, 7, 1, 3, 6], Pivot = 6. Partitioning results in [4, 2, 0, 1, 3] | 6 | [8, 7].
  2. Left partition [4, 2, 0, 1, 3], Pivot = 3. Partitioning results in [2, 0, 1] | 3 | [4].
  3. Left partition [2, 0, 1], Pivot = 1. Partitioning results in [0] | 1 | [2].
  4. Right partition [8, 7], Pivot = 7. Partitioning results in [7] | 8.
  5. Final sorted list: [0, 1, 2, 3, 4, 6, 7, 8].

Best Case Time Efficiency:

The best case occurs when the pivot consistently divides the array into two nearly equal halves. The recurrence relation is:

T(n) = 2T(n/2) + Θ(n)

Using the Master Theorem, where a=2, b=2, and f(n)=n, we have n^log_b(a) = n^1. Since f(n) = Θ(n^log_b(a)), the best-case time complexity is O(n log n).

2

Consider the following recurrence

T(n) = 3T(n/3) + n

Obtain asymptotic bound using substitution method.

15 marks

Answer

To solve the recurrence T(n) = 3T(n/3) + n using the substitution method, we first guess the asymptotic bound. Based on the Master Theorem structure, we hypothesize that T(n) = O(n log n).

We must prove that T(n) ≤ c n log n for some constant c > 0. We assume the inductive hypothesis holds for smaller values, specifically T(n/3) ≤ c(n/3) log(n/3).

Substituting this into the recurrence:

T(n) ≤ 3(c(n/3) log(n/3)) + n

Simplifying the expression:

T(n) ≤ cn log(n/3) + n
T(n) ≤ cn(log n - log 3) + n
T(n) ≤ cn log n - cn log 3 + n

For the inequality T(n) ≤ cn log n to hold, we require:

-cn log 3 + n ≤ 0
n(1 - c log 3) ≤ 0

This holds true when 1 - c log 3 ≤ 0, which implies c ≥ 1/log 3. By choosing a constant c that satisfies this condition and selecting an appropriate base case, we confirm that T(n) = O(n log n).

3

Using disjoint-sets find the connected components in the undirected graph G = (V, E), where the vertices V = {a, b, c, d, e, f, g, h, i, j} and edges E = {(a, c), (a ,b), (e, f), (h, i), (e, g), (a, d), (e, d) (b, d), (c, a), (h, j)}. The edges are processed in the order given. List the vertices in each connected component after each step.

15 marks

Answer

Sign in to view the complete answer paper.

4

Find a solution to the 8-Queens problem using backtracking strategy. Draw the solution space using necessary bounding function.

15 marks

Answer

Sign in to view the complete answer paper.

5

Suppose we run Dijkstra’s single source shortest-path algorithm on the following edge weighted directed graph with vertex P as the source (figure 1). In what order do the nodes get included into the set of vertices for which the shortest path distances are finalized?

15 marks

Answer

Sign in to view the complete answer paper.

6

A thief enters a house for robbing it. He can carry a maximal weight of 60 kg into his bag. There are 5 items in the house with the following weights and values. What items should thief take if he can even take the fraction of any item with him? (w1, w2, w3, w4, w5) = (5, 10, 15, 22, 25), (b1, b2, b3, b4, b5) = (30, 40, 45, 77, 90).

15 marks

Answer

Sign in to view the complete answer paper.

7

Given a set of cities and distance between every pair of cities, the problem is to find the shortest possible route that visits every city exactly once and returns to the starting point. (figure 2)

15 marks

Answer

Sign in to view the complete answer paper.

8

Given a set of 4 items, each with weight {2, 2, 4, 5} and benefit {3, 7, 2, 9}, Using LC branch and Bound determine the items to include in the knapsack so that the total weight is less than or equal to a given weight limit and the total benefit is maximized. The weight limit for this knapsack is 10?

15 marks

Answer

Sign in to view the complete answer paper.

About this paper

This page contains the question paper of DESIGN AND ANALYSIS OF ALGORITHMS from JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD for B. Tech CSE III I, September - 2021, R16.

For the solved question paper with answers, switch to the Answer Paper tab.

Other papers in DESIGN AND ANALYSIS OF ALGORITHMS

Loading Question Papers

Fetching data from database...