Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

Divide and Dynamic

Sl.No Greedy Algorithm conquer Programming

Follows Top-down Follows Top-down Follows bottom-up


1
approach approach approach

Used to solve Used to solve Used to solve


2
optimization problem decision problem optimization problem

Sub problems do not Subproblems are subproblems are


3
overlap independent. dependent

It may or may not Solutions of Solution to


4 generate an optimal subproblems are not subproblems are stored
solution. stored in table

5 Non recursive in nature. Recursive in nature. Recursive in nature.

It solves subproblems only


efficient and fast than less efficient and
6 once and then stores in
divide and conquer. slower. the table.

more memory is
extra memory is not some memory is required to store
7
required. required. subproblems for later
use.

Examples: Knapsack Examples: Merge Examples,


8
problem sort Matrix multiplication.
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.

G is usually assumed to be a weighted graph. In this graph, cost of an edge (i, j) is represented by c(i,
j). Hence, the cost of path from source s to sink t is the sum of costs of each edges in this path.

The multistage graph problem is finding the path with minimum cost from source s to sink t.
N - Queens problem is to place n - queens in such a manner on an n x n chessboard that no queens
attack each other by being in the same row, column or diagonal.It can be seen that for n =1, the
problem has a trivial solution, and no solution exists for n =2 and n =3. The eight queens problem is
the problem of placing eight queens on an 8×8 chessboard such that none of them attack one
another (no two are in the same row, column, or diagonal). There are different solutions for the
problem. There are 92 solutions.

You might also like