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

Algorithm Analysis and Design Exam 2021

This document contains an exam for the subject Analysis and Design of Algorithms. The exam contains 5 questions testing knowledge of key algorithms topics. Question 1 covers algorithm definition, analysis of algorithms complexity, and insertion sort. Question 2 covers selection sort, heap sort, and quick sort. Question 3 covers dynamic programming, the knapsack problem, and longest common subsequence. Question 4 covers greedy algorithms, minimum spanning trees, and backtracking. Question 5 covers graph theory concepts, string matching algorithms, and complexity classes. The exam tests a wide range of algorithms and requires implementation, analysis, and explanations of different algorithms.

Uploaded by

Shiv Patel
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)
48 views2 pages

Algorithm Analysis and Design Exam 2021

This document contains an exam for the subject Analysis and Design of Algorithms. The exam contains 5 questions testing knowledge of key algorithms topics. Question 1 covers algorithm definition, analysis of algorithms complexity, and insertion sort. Question 2 covers selection sort, heap sort, and quick sort. Question 3 covers dynamic programming, the knapsack problem, and longest common subsequence. Question 4 covers greedy algorithms, minimum spanning trees, and backtracking. Question 5 covers graph theory concepts, string matching algorithms, and complexity classes. The exam tests a wide range of algorithms and requires implementation, analysis, and explanations of different algorithms.

Uploaded by

Shiv Patel
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

Seat No.: ________ Enrolment No.

___________

GUJARAT TECHNOLOGICAL UNIVERSITY


BE - SEMESTER–V (NEW) EXAMINATION – WINTER 2021
Subject Code:3150703 Date:17/12/2021
Subject Name:Analysis and Design of Algorithms
Time:02:30 PM TO 05:00 PM Total Marks: 70
Instructions:
1. Attempt all questions.
2. Make suitable assumptions wherever necessary.
3. Figures to the right indicate full marks.
4. Simple and non-programmable scientific calculators are allowed.
MARKS
Q.1 (a) Define algorithm. Discuss key characteristics of algorithms. 03
(b) Explain why analysis of algorithms is important? Explain: Worst Case, Best 04
Case and Average Case Complexity with suitable example.
(c) Write and analyze an insertion sort algorithm to arrange n items into 07
ascending order.

Q.2 (a) Write an algorithm of Selection Sort Method. 03


(b) Sort the following numbers using heap sort. 04
20, 10, 50, 40, 30
(c) Sort the following list using quick sort algorithm: <50, 40, 20, 60, 80, 100, 07
45, 70, 105, 30, 90, 75> Also discuss worst and best case of quick sort
algorithm.
OR
(c) Apply merge sort algorithm on array A = {2,7,3,5,1,9,4,8}. What is time 07
complexity of merge sort in worst case?
Q.3 (a) What is Principle of Optimality? Explain its use in Dynamic Programming 03
Method
(b) Explain Binomial Coefficient algorithm using dynamic programming. 04
(c) Solve the following 0/1 Knapsack Problem using Dynamic Programming. 07
There are five items whose weights and values are given in following arrays.
Weight w [] = {1,2,5,6,7} Value v [] = {1, 6, 18, 22, 28} Show your
equation and find out the optimal knapsack items for weight capacity of 11
units.
OR
Q.3 (a) Compare Dynamic Programming Technique with Greedy Algorithms 03
(b) Give the characteristics of Greedy Algorithms. 04
(c) Obtain longest common subsequence using dynamic programming. Given A 07
= “acabaca” and B = “bacac”.
Q.4 (a) Using greedy algorithm find an optimal schedule for following jobs with n=7 03
profits: (P1, P2, P3, P4, P5, P6, P7) = (3, 5, 18, 20, 6, 1, 38) and deadline
(d1, d2, d3, d4, d5, d6, d7) = (1, 3, 3, 4, 1, 2, 1)
(b) Find Minimum Spanning Tree for the given graph using Prim’s Algo. 04

1
(c) Explain in brief Breadth First Search and Depth First Search Traversal 07
techniques of a Graph with Example.
OR
Q.4 (a) Find an optimal Huffman code for the following set of frequency. A : 50, b: 03
20, c: 15, d: 30
(b) Find Minimum Spanning Tree for the given graph using Kruskal Algo. 04

(c) Explain Backtracking Method. What is N-Queens Problem? Give solution 07


of 4- Queens Problem using Backtracking Method
Q.5 (a) Define Articulation point, Acyclic Directed Graph, Back Edge 03
(b) Show the comparisons that naïve string matcher makes for the pattern 04
p=0001 in the text T=000010001010001
(c) Explain spurious hits in Rabin-Karp string matching algorithm with 07
example. Working modulo q=13, how many spurious hits does the Rabin-
Karp matcher encounter in the text T = 2359023141526739921 when
looking for the pattern P = 31415?
OR
Q.5 (a) Explain polynomial reduction. 03
(b) Differentiate branch and bound and back tracking algorithm. 04
(c) Explain P, NP, NP complete and NP-Hard problems. Give examples of each 07

*************

Common questions

Powered by AI

Kruskal’s Algorithm finds a Minimum Spanning Tree (MST) by sorting all edges in increasing order of weight, then adding edges to the MST, provided adding them does not form a cycle, until all vertices are included. It differs from Prim’s Algorithm, which grows the MST by starting from a single vertex and adding the cheapest edge from the growing MST to a vertex not yet in it. Kruskal's approach focuses on edges and their weights globally, while Prim's expands the tree from a specific node locally .

Understanding the concept of NP-completeness is crucial in computational complexity theory because it helps identify problems for which no efficient solution algorithm is known. NP-complete problems are significant as they lie at the intersection of NP problems, wherein it is hard to find solutions but easy to verify them. If any NP-complete problem can be solved in polynomial time, then all problems in NP can be solved efficiently. Thus, NP-completeness highlights the boundary between feasible and infeasible computations, guiding research and resource allocation .

Dynamic programming solves problems by breaking them down into overlapping subproblems, solving each subproblem once, and storing their solutions. It is used for optimization problems where solutions to subproblems can be reused. Greedy algorithms, on the other hand, build up a solution piece by piece, always choosing the next piece that offers the most immediate benefit. While greedy algorithms are generally faster, they do not always provide an optimal solution, whereas dynamic programming does, although at usually higher computational cost .

The analysis of algorithms is crucial because it helps determine their efficiency by analyzing the time and space they consume. It contributes to understanding their efficiency through worst-case, best-case, and average-case complexity. The worst-case complexity provides the maximum time needed, best-case gives the minimum, and average-case offers an expectation of the time for typical inputs. Analyzing these scenarios allows developers to predict the algorithm's performance, optimize resource usage, and make informed decisions when choosing algorithms .

The principle of optimality in dynamic programming states that an optimal solution to any problem consists of optimal solutions to its subproblems. This means breaking down a problem into smaller, more manageable parts that can be solved individually and combined. An example is the 0/1 Knapsack Problem, where the optimal solution for a knapsack of given capacity is built from optimal solutions of smaller capacities. By using dynamic programming, one can store solutions to subproblems and use them to build up solutions to larger ones, thus ensuring efficiency and optimality .

Backtracking is a recursive, depth-first search technique for solving computational problems, where solutions are incrementally built, abandoned when a conflict arises, and systematically tried in different configurations. In the N-Queens Problem, backtracking involves placing queens one by one in different columns, reverting if a placement leads to a conflict, and trying the next possibility. For a 4-Queens configuration, a queen is placed in the first row, and the algorithm moves to the next row, checking safe positions, and backtracks when necessary until all queens are placed safely without threats .

The key characteristics of an algorithm include definiteness, which ensures that each step is precisely stated; input, as an algorithm must take at least zero or more inputs; output, resulting in one or more results; finiteness, ensuring the algorithm has an end; and effectiveness, meaning that all operations are basic enough to be performed in a finite amount of time. These characteristics are significant because they ensure that the algorithm can perform tasks accurately and efficiently, making it a reliable solution in computer science problems .

A Huffman code is constructed by creating a binary tree where each leaf represents a character from the set, and the path from the root to a leaf corresponds to the binary code for that character. Nodes are created by merging the two least frequent nodes, repeating this until one node remains. For the frequencies given (A: 50, b: 20, c: 15, d: 30), nodes are merged starting with the smallest frequencies. This results in prefix-free codes that map more frequent characters to shorter codes, making the Huffman code optimal for data compression by reducing the total bit count needed for storage .

Understanding spurious hits in the Rabin-Karp algorithm is important because they can lead to false positive matches, affecting the algorithm’s efficiency. Spurious hits occur when substrings have identical hash values but do not match. By checking the actual content of the substrings when hash values match, these spurious hits can be determined and eliminated. This allows the algorithm to efficiently find occurrences of a pattern within a text without unnecessary computations on incorrect substrings .

The LCS problem can be solved using dynamic programming by constructing a matrix that represents all possible pairs of prefixes of the two strings. Through this matrix, subproblems are solved and combined to build up to the solution for the entire strings. For the strings A = 'acabaca' and B = 'bacac', the dynamic programming method involves filling the matrix such that the value at each cell represents the length of the LCS of the prefixes. The filled matrix can then be traced back from the bottom-right to determine the LCS, which is 'bcac' in this case .

You might also like