0% found this document useful (0 votes)
13 views8 pages

cs3401 Unit3

The document discusses various algorithm design techniques including Divide and Conquer, Dynamic Programming, and Greedy Techniques. It outlines specific algorithms such as Quick Sort, Merge Sort, and their advantages and disadvantages, as well as the principles of dynamic programming and greedy algorithms. Additionally, it includes definitions, comparisons, and examples related to these methodologies.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views8 pages

cs3401 Unit3

The document discusses various algorithm design techniques including Divide and Conquer, Dynamic Programming, and Greedy Techniques. It outlines specific algorithms such as Quick Sort, Merge Sort, and their advantages and disadvantages, as well as the principles of dynamic programming and greedy algorithms. Additionally, it includes definitions, comparisons, and examples related to these methodologies.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

UNIT III

ALGORITHM DESIGN TECHNIQUES

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. Give the general plan for divide-and-conquer algorithms. (AU-APRIL/MAY


2021) (NOV/DEC 2023) (MAY/JUNE 2016) (R) (Nov 17)
The general plan is as follows.
 Divide the problem into a number of subproblems that are smaller instances of
the same problem.
 Conquer the subproblems by solving them recursively. If they are small
enough, solve the subproblems as base cases.
 Combine the solutions to the subproblems into the solution for the original problem.
2. List the advantages of Divide and Conquer Algorithm.
Solving difficult problems, Algorithm efficiency, Parallelism, Memory access,
Round off control.
3. Give the recurrence relation of divide-and-conquer? (R)
The recurrence relation is
g(n) if n is small

T(n) = t(n1) + t(n2)+ ..... + t(nk) +F(n) when n is sufficiently large.
4. Define feasibility.
Feasibility indicates that it is practical and capable of being executed within reasonable
constraints and resources.
5. Define Quick Sort.
QuickSort is a sorting algorithm based on the Divide and Conquer that picks an
element as a pivot and partitions the given array around the picked pivot by placing
the pivot in its correct position in the sorted array.

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

The splitting of a array of


The partition of In the merge sort, the
elements is in any ratio, not
elements in the array is parted into
necessarily divided into
array just 2 halves (i.e. n/2).
half.

Worst case
O(n^2) O(nlogn)
complexity

It works well on smaller It operates fine on any


Works well on
array size of array

It work faster than other


It has a consistent
Speed of sorting algorithms for small
speed on any size of
execution data set like Selection sort
data
etc

8. Define Merge sort. (R)


Merge sort sorts a given array A[0..n-1] by dividing it into two halves a[0..(n/2)-
1] and A[n/2..n-1] sorting each of them recursively and then merging the two
smaller sorted arrays into a single sorted one.
9. List the Steps in Merge Sort

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.

Recursion Step: Recursively sort array A1 and A2.

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

11. List out the Advantages in Quick Sort


 It is in-place since it uses only a small auxiliary stack.
 It requires only n log(n) time to sort n items.
 It has an extremely short inner loop

This algorithm has been subjected to a thorough mathematical analysis, a very


precise statement can be made about performance issues.
12. Describe the recurrence relation of merge sort? (R)
If the time for the merging operation is proportional to n, then the computing time
of merge sort is described by the recurrence relation
T(n)= a
2T(n/2)+n n = 1, a constant
13. State Master’s theorem. (APR/MAY 18)
If f(n) θ(nd) where d ³ 0 in recurrence equation T(n) = aT(n/b)+f(n),
then θ (nd) if a<bd T(n) θ (ndlog n) if a=bd
θ (nlog ba) if a>bd

The efficiency analysis of many divide-and-conquer algorithms is greatly simplified by


the use of Master theorem.
14. List out the Disadvantages in Quick Sort
• It is recursive. Especially if recursion is not available,
the implementation is extremely complicated.
• It requires quadratic (i.e., n2) time in the worst-case.
• It is fragile i.e., a simple mistake in the implementation can go unnoticed
and cause it to perform badly.
15. What are the differences between dynamic programming and divide and
3
conquer approaches? (NOV/DEC 2023)

DDYDYNAMIC PROGRAMMING DI DDYDIVIDE & CONQUER VIDDI

In this technique, the problem is divided


into small subproblems. These subproblems
In dynamic programming, many decision
are solved independently. Finally, all the
sequences are generated, and all the
solutions of subproblems are combined
overlapping sub instances are considered.
together to get the final solution to the given
problem.

In this method, duplications in sub solutions


In dynamic programming, duplications in
are neglected, i.e., duplicate sub solutions
solutions are avoided totally.
can be obtained.

Divide and conquer strategy is less efficient


Dynamic programming is more efficient
than the dynamic programming because we
than Divide and conquer technique.
have to rework the solutions.

It is the non-recursive approach. It is a recursive approach.

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.

 It definitely gives the optimal solution always.


19. What are the drawbacks of Dynamic programming? (R)
 Time and space requirements are high, since storage is needed for all level.

 Optimality should be checked at all levels.


20. Write the general procedure of D ynamic programming.(APR/MAY 2017) (R)
The development of dynamic programming algorithm can be broken into a
sequence of 4 steps.
 Characterize the structure of an optimal solution.

 Recursively defines the value of the optimal solution.


 Compute the value of an optimal solution in the bottom-up fashion.
 Construct an optimal solution from the computed information.
21. What is the difference between dynamic programming and
greed algorithm?(APRIL/MAY 2012) (AN)

Dynamic Programming Greedy Method

1. Dynamic Programming is used to 1. Greedy Method is also used to get the


obtain the optimal solution. optimal solution.

2. In Dynamic Programming, we choose at2. In a greedy Algorithm, we make whatever


each step, but the choice may depend choice seems best at the moment and then
on the solution to sub-problems. solve the sub-problems arising after the
choice is made.

3. Less efficient as compared to a greedy 3. More efficient as compared to a greedy


approach approach

4. Example: 0/1 Knapsack 4. Example: Fractional Knapsack

5. It is guaranteed that Dynamic5. In Greedy Method, there is no such


Programming will generate an optimal guarantee of getting Optimal Solution.
solution using Principle of Optimality.
22.Define Optimal Binary Search Trees (R)
The time required to search a node in BST is more than the balanced binary search tree as a
balanced binary search tree contains a lesser number of levels than the BST. There is one way
that can reduce the cost of a binary search tree is known as an optimal binary search tree.
23. List out the memory functions used under Dynamic programming. (MAY 2015) (R)

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.

25. Define Optimization function


Every set of s that satisfies the constraints is a feasible solution.
Every feasible solution that maximizes is an optimal solution.
26. Define Greedy Methodology
Greedy algorithms are simple and straightforward.
They are short sighted in their approach
A greedy algorithm is similar to a dynamic programming algorithm, but the difference
is that solutions to the sub problems do not have to be known at each stage, instead a
"greedy" choice can be made of what looks best for the moment.

27.Write the Greedy Properties(Elements)


It consists of two property,
1. "greedy-choice property" ->It says that a globally optimal solution can be arrived at
by making a locally optimal choice.
2. "optimal substructure" ->A problem exhibits optimal substructure if an
optimal solution to the problem contains optimal solutions to the sub-problems.
are two ingredients in the problem that lend to a greedy strategy.

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.

31.State the principle of optimality. (APR/MAY 2019)

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.

3. Explain merge sort with suitable example. .(AU-APR/MAY2023)


4. Explain quick sort with suitable example.
5. What is dynamic Programming? Explain dynamic programming solution for matrix chain
multiplication.(AU-APR/MAY2023)
6. Explain briefly multistage graph with suitable example.
7. What is meant by optimal binary search tree? Explain with suitable example.
8. What is Huffman tree? Outline the steps to build a Huffman tree using greedy algorithm design
paradigm with an example.

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)

You might also like