cs3401 Unit3
cs3401 Unit3
Divide and Conquer methodology: Finding maximum and minimum - Merge sort - Quick
sort Dynamic programming: Elements of dynamic programming — Matrix-chain
multiplication - Multi stage graph — Optimal Binary Search Trees. Greedy Technique:
Elements of the greedy strategy - Activity-selection problem –- Optimal Merge pattern
— Huffman Trees.
PART A
1
6. List out the Disadvantages in Quick Sort
i. It is recursive. Especially if recursion is not available,
the implementation is extremely complicated.
ii. It requires quadratic (i.e., n2) time in the worst-case.
iii. It is fragile i.e., a simple mistake in the implementation can
go unnoticed and cause it to perform badly.
7. What is the difference between quicksort and mergesort?
Basis for
comparison Quick Sort Merge Sort
Worst case
O(n^2) O(nlogn)
complexity
Divide Step: If given array A has zero or one element, return S; it is already sorted.
Otherwise, divide A into two arrays, A1 and A2, each containing about half of the
elements of A.
2
Conquer Step: Combine the elements back in A by merging the sorted arrays A1 and
A2 into a sorted sequence
10. List out Disadvantages of Divide and Conquer Algorithm
Conceptual difficulty
Recursion overhead
Repeated
subproblems
It uses the bottom-up approach of problem- It uses the top-down approach of problem-
solving. solving.
.
16. What is the time and space complexity of Merge sort? (APR/MAY 2019)
Time complexity = θ(n log
n) Space complexity =
n+log2n
=θ(n)
17. Define dynamic programming. (APR/MAY 2017) (R)
Dynamic programming is an algorithm design method that can be used when a
solution to the problem is viewed as the result of sequence of decisions.
18. What are the features of dynamic programming? (R)
Optimal solutions to sub problems are retained so as to avoid re-computing their
values.
4
Decision sequences containing subsequences that are sub optimal are not considered.
5
Memory functions solve in a top-down manner only sub problems that are
necessary. Memory functions are an improvement of dynamic programming because they
only solve sub problems that are necessary and do it only once. However they require
more because it makes recursive calls which require additional memory.
Greedy Algorithm
Branch and Bound
Genetic Algorithm
24.State the general principle of greedy algorithm. (NOV/DEC 16) (R)
The general structure of a greedy algorithm can be summarized in the following
steps:
Identify the problem as an optimization problem where we need to find the best
solution among a set of possible solutions.
Determine the set of feasible solutions for the problem.
Identify the optimal substructure of the problem, meaning that the optimal solution to
the problem can be constructed from the optimal solutions of its subproblems.
Develop a greedy strategy to construct a feasible solution step by step, making the
locally optimal choice at each step.
6
28.State feasible and constraint
Feasible: A feasible solution satisfies the problem’s constraints
Constraints: The constraints specify the limitations on the required solutions
29.Write the Pseudo-code for Greedy Algorithm
Algorithm Greedy (a,n)
//a[1:n]contains the n inputs.
{
solution:=0;//initialize the solution. for
i:=1 to n do
{
x:=Select(a);
if Feasible( solution, x) then solution:=Union(solution,x);
}
return solution
30. Define multistage graphs. Give an example. (NOV/DEC 2018)
A multistage graph G = (V, E) is a directed graph where vertices are partitioned into
k (where k > 1) number of disjoint subsets S = {s1,s2,…,sk} such that edge (u, v) is in E,
then u Є si and v Є s1 + 1 for some subsets in the partition and |s1| = |sk| = 1.
The vertex s Є s1 is called the source and the vertex t Є sk is called sink.
The principles of optimality states that “in an optimal sequence of decisions or choices, each
subsequence must be optimal”
7
16 Marks (Refer class notes)
1. What is meant by divide &conquer Methodolgy? Explain.
2. Find the maximum and minimum element from the given set of elements.
Review
1. Define divide and conquer to apply the technique in binary search algorithm and to analysis
it. (APR/MAY 2006) (APR/MAY 2017) (R)
2. Explain in detail in merge sort give an example (APR/MAY 2008) (MAY 2016). (R)
3. What is divide and conquer strategy and explain the binary search with suitable example problem.
(NOV/DEC 2011) (R)
4. Distinguish between Quick sort and Merge sort, and arrange the following numbers in increasing
order using merge sort. (18, 29, 68, 32, 43, 37, 87, 24, 47, 50) (NOV/DEC
2011) (MAY/JUNE 2013). (A)
5. Trace the steps of Mergesort algorithm for the elements 122,25,70,175,89,90,95,102,123 and also
compute its time complexity.(NOV/DEC 2012) (A) (Nov 17) (Apr 18)
6. Write an algorithm to perform binary search on a sorted list of elements. Analyze the algorithm
for the best case, average case and worst case.(APR/MAY 2011). (AN)