NP Problems (Non Deterministic
problem)
Department of Computer Applications
School of Physical Sciences
Sikkim University Presented By - :
Robin Gurung
14UCA015
NP problems
1. Graph colouring.
2. Bin Packing Problem.
n 0 1 2 3
0 1 1 0 1
1 1 1 1 1
2 0 1 1 1
3 1 1 1 1
3 2
10 Graphcolor(int k)
{
for(Int c =1 ;c<=m;c++)
{
if (isSafe(k,c)){
x[k]=c;
if((k+1))<n)
Graphcolor(k+1)
else
print x[]; return
}
}
}
k =Current node
c =colour
n = total nodes
0 1 2
1 2 3X[k]=
ifSafe(int k, int c)
{
for(int i=0;i<n;i++)
{
if(G[k][i] ==1 && c==x[i])
{
return false;
}
}
return true;
}
•Only feasible to small problem like this.
•This graph colouring problem is known as NP hard
problem.
•This algorithm is still O(𝑚 𝑛
)
•m = no. of colours
•n = no. of vertices.
Conclusion of Graph colouring
Bin packing Problem
• Fitting things efficiently and neatly inside a larger
container.
• 6 group of people ,of group size 3,1,6,4,5 and 2 need
to fit onto a minibuses with capacity 7 must stay
together in their groups. Find a number of buses need
to pack them in efficiently and so that each group
stays together.
Bin packing algorithm
•Lower Bound of a problem.
•Perform first fit algorithm.
•Perform first fit decreasing algorithm.
•Full bin packing algorithm.
Lower bound
3
2
5
4
6
1
+
+
+
+
+
21
+
7
7
7
7
21 /7 =3
3 is lower bound
MinibusesGroups
First fit algorithm
3
2
5
4
6
1
* Occupied 4 minibuses
* 7 waste spaces
MinibusesGroups
First fit decreasing algorithm
MinibusesGroups
Full bin packing
MinibusesGroups
Conclusion of bin packing algorithm
• First fit algorithm :-
I. quick and easy to perform.
II. Does not lead to optimal solution.
• First fit decreasing algorithm
I. quick and easy to perform.
II. Usually better than first fit algorithm.
III. does not get optimal solution.
• Full bin packing algorithm
I. usually get good solution.
II. cant be difficult to perform if numbers are awkward.

Non Deterministic and Deterministic Problems

  • 1.
    NP Problems (NonDeterministic problem) Department of Computer Applications School of Physical Sciences Sikkim University Presented By - : Robin Gurung 14UCA015
  • 2.
    NP problems 1. Graphcolouring. 2. Bin Packing Problem.
  • 3.
    n 0 12 3 0 1 1 0 1 1 1 1 1 1 2 0 1 1 1 3 1 1 1 1 3 2 10 Graphcolor(int k) { for(Int c =1 ;c<=m;c++) { if (isSafe(k,c)){ x[k]=c; if((k+1))<n) Graphcolor(k+1) else print x[]; return } } } k =Current node c =colour n = total nodes 0 1 2 1 2 3X[k]= ifSafe(int k, int c) { for(int i=0;i<n;i++) { if(G[k][i] ==1 && c==x[i]) { return false; } } return true; }
  • 4.
    •Only feasible tosmall problem like this. •This graph colouring problem is known as NP hard problem. •This algorithm is still O(𝑚 𝑛 ) •m = no. of colours •n = no. of vertices. Conclusion of Graph colouring
  • 5.
    Bin packing Problem •Fitting things efficiently and neatly inside a larger container. • 6 group of people ,of group size 3,1,6,4,5 and 2 need to fit onto a minibuses with capacity 7 must stay together in their groups. Find a number of buses need to pack them in efficiently and so that each group stays together.
  • 6.
    Bin packing algorithm •LowerBound of a problem. •Perform first fit algorithm. •Perform first fit decreasing algorithm. •Full bin packing algorithm.
  • 7.
    Lower bound 3 2 5 4 6 1 + + + + + 21 + 7 7 7 7 21 /7=3 3 is lower bound MinibusesGroups
  • 8.
    First fit algorithm 3 2 5 4 6 1 *Occupied 4 minibuses * 7 waste spaces MinibusesGroups
  • 9.
    First fit decreasingalgorithm MinibusesGroups
  • 10.
  • 11.
    Conclusion of binpacking algorithm • First fit algorithm :- I. quick and easy to perform. II. Does not lead to optimal solution. • First fit decreasing algorithm I. quick and easy to perform. II. Usually better than first fit algorithm. III. does not get optimal solution. • Full bin packing algorithm I. usually get good solution. II. cant be difficult to perform if numbers are awkward.