DAA Unit - 5
DAA Unit - 5
↳
solving
TSP
↳
Max clique concept
Randomized
Algorithm
↳
Quick sort
Natural
Algorithms
Algorithm
&
Evolutionary computing
↳
Genetic
Algorithms
Annealing
simulated
* Approximation
Algorithm
:
hard
% NP
-
NP
-
to
NP-complete
An approximation algorithm
is
way of
→ a
approach NP -
completed for
the
optimization
problem .
guarantee
This does not the
technique
→
best sot .
the
goal of approximation algorithm
→
an
is to
to come as close as
possible
the seasonable
optimum value in a
is at the most
aunt time which
of
time
polynomial .
approximation
algo
such 's are called as
or heuristic
algo .
the
→ For the vertex cover problem ,
the
optimization problem is to
find
vertices and
vertex cover with fewest
is to
the
approximation problem
vertex
find the vertex cover with few .
→
suppose we work on a
optimization
lost
problem where sofa carries a
every
returns
An
approximation algorithm
a
may
not be optimal
For
example
→ :
for minimum
suppose we are
considering a
size vertex -
cover ( ve ) .
An approximate
for but the
algorithm return a ve us
,
may "
the Sol returned
→ Let C be the cost of
by an
approximate algorithm
* "
( Sol
is the cost
of optimal
size
Plut ifp
~
is
approximation for an
*
e) Mohini zatiae → (
⇐ P (a)
c-
e) Maximization →
C- =P (a)
*
[
3) P In ) & I
* Vertex cover Problem : A cover of a
graph
is subset which cover
a
of vortex every
min size vertex
edge VC
problem
is the .
cover .
Approximation -
cover -
problem (G) :
C ← of is
B C
D
⑤=E[gT
white
c)
'
E
-1-4 ( B.
E
arbitrary
F
do let an a-
in
'
edge E
c ← c u { a. u
} C =
to U { B. c } =/ Be}
remove from E
'
every
edge incident either u.ie } remove B
B
-
-
E
C
-
D
return C c- F
( u
, v1 =
} E ,
F
}
C. =
} B. C
} U I E
,
F}
F
=
? B ,
C
,
E. }
Next loop ,
lui } =
II. G }
C
:{ B. c. E. F } U { D. G }
-
I B
,
C. 7 ,
E. F
,
G }
How we
select B F
,
,
D
B V C H
D
"
=
A
= =
E F G-
wu°u= 3 *
,
( = 6 C = 3
,
*
Pln ) (
minimization
§
=
= =
2
e-
* Christofides
Algorithm
:
Sd
"
Brute-force Optimal ✓
Algorithm
→
time ✗
Really long
✓
Heuristic
Algorithm -
polynomial
time
( Brute
force ) suboptimal approximate
✗
Approximation -
Polynomial time ✓
algorithm for
finding
is
→ It an
approximate
salesman
traveling problem
-
Sd to the
,
on
didst metric
"
space
.
optimal
sun
a
factor of 3/2 of the
length .
- still stands as the best polynomial time
approximation algo .
the
- Let
,
G- =
Cv ,
w ) be an instance
of
is complete
is G-
graph
a
TSP . That
V vertices and
f.
±
the set of the .
.
on
real wt
negative
-
to
assigns
w a non -
every edge of G- .
in
equality for every
According
to the
triangle
-
case that
w Luv ) + w( un ) z w ( )
use
all
connects
→ Pseudo Code :
vertices together
without any
☒ {T
" "
of vertices
' with no
odd
-
7 cycle
are
1)
ofeage Gi
an
Create
tour
that
a wot ages
lemma
degree in T .
By the
handshaking
no
of vertices
µj÷ ÷ ÷ ÷:É!¥÷:*
.
even
.
O has an :* .
I Find a
min - wt .
perfect matching
in the induced by
subgraph given multi
having
-
edges .
>
Graph
and form
edges M T to a
4) Combine the
of
which each
in
connected multi u
graph
-
"
that "
+
tra '
"
ends
Eulerian & "
"
edge
degree
vertex has even starts F"
" every
game
visits
.
Eulerian qq.fm
vortex once
.
exactly
Form an
shortuettiug~vis.it
each
result .
As such the heuristic can
give several diff path .
Problem
*
Approximating Max clique :
in which all
pains
A clique is
subgraph
→ a
of vertices are
mutually adjacent
- sub
graph of graph
where the sub
graph
-
-
a ,
is
complete
is called as
clique
graph
.
a ,
_→••
connected to each
other
14 In '
IE1
¥Y
=
Eg
:
I 2
I 2- 3- 4 =)
-
complete Graph
5
subgraph of
1- 2-
3-
4- 5
4
3
A set
→ Max -
clique is a
of objects which
related in
specific
mutually
are some
criterion .
The that
largest
can
- size
of the clique
be made
of and vertices of
up edges
G- is called the
clique
no .
of G-
→ NP -
Complete problem .
where the
→ Real life problem : social nlw ,
and the
's vertices represents people
graph
" mutual acquaintances
graph edges represent
:
Bioinformatics .
:
computational chemistry
→ Other methods :
Greedy
:
in
adjacent
to
: Recursive C. C.
"
- 3 nodes "
a
- d- add
•
R ✗ to
the p
added
"
nodes
in
current dive
turf a pod
"
per qui
nodes course, c.
is
→ Decision Problem :
find if a
graph
size
having a
clique of -
K .
in
Problem find Max clique a
Optimization
:
→
graph
.
→ SAT ✗ CDP
*
Me 22 ,
✗
3
,
F = die :
9--1
F ( (I ✓ Iz ) ^ ( see V23 )
= ✗
,
V ke ) n
( i
C 2 C3
G- ! V =
{ < a. i> / a c- C :}
: E =
{ < a. i >
,
< b.
j > I itj
& btñ }
⇐ ,
2 > < Ñ ,
27
True
CK ,
I >
< hi 37
,
CU2 1) ,
True LK3 ,
3 >
True
k①
with K clocks
If you take
problem
-
→
a
,
cliques .
- Reverse Sol
"
:
hi V2 ✗
3
to
0 ? {
F= ↳ v1 ) n
( i v0 ) n ( Ovi )
= I n I ^ I
I
=
* Randomized
Algorithm
:
A that randomness as a
-
technique uses
part of its
logic
.
→
It is used to reduce time ? space complexity
- An
algorithm known as amplification
is used in order to boost the probability
runtime
by sacrificing
.
correctness
of
the randomized
- It works by repeating random
several times with diff
algo
sub
samples of the ilp ,
and compromising
their results .
* Types of randomized
Algorithm
:
-
I.
i Carlo
Monte
Las
Vegas *
*
for
given :( p
a
for a
given :( p Algo whose
running time
running
me
ofp is
fixed , is deterministic ,
&
Mp /
running time
may ofp is variable
random
* Randomized Quick sort :
→ TC :
0 Cue )
Tcu ) =
T ( n -
1) + c. in
RQS introduced
complexity
was
- To reduce the ,
- Pseudo Code :
RQS ( A , p .
q ) {
Greatest Function
if Cpaq) 1- Random
r= RGFCP g) ,
swap ( A [ P]
,
Acr )
m=
partition ( A. P , a)
RQS ( A ,
P ,
m -
1)
RQS ( A ,
m -11
,
a)
}
}
in
seq
generate
no .
will
.
Assumption
never
-
: RGF
worst
(
login )
.
Tc 0
→ :
n
distinct
-
.
same .
Q An distinct is
array of
. 25 element to be
that the
pivot
element
gets
probability worst possible
location in the
the
placed in
( rounded off to
first
round
of partitioning
places )
is
2 decimal -
is min :
- is > f- element
c)✗l
element is
e) If Max :
(n-_
"
Sol : 0.08
⇐
=
that
computer-based problem solving system
use computational models
of evolutionary
process .
candidate
representing
a
→ chromosome : individual ,
sot
chromosomes
-
Population : d- set of .
chromosome
fundamental building
block
of
gene
→ :
each
each in a chromosome reprints
gene smallest
is the
variable to be
optimized .
It
unit
of information .
*
Optimization Problems :
Problems
sample Optimization
:
-
I TSP
2)
3) Graph Colouring
Knapsack 4)
Assignment
Job Machine
5) Coin
change 6) BST construction
→
limitation of traditional optimization
approach
:
I
computationally expensive
e) Methods fail for discontinuous
objective f± .
3)
May not be suitable for parallel computing
handle
4) Discrete variables are difficult to .
1- Behaviour
Behaviour Physical
Biological
!| ←
"
/ f. \ Artificial
stimulated
Annealing
Ant
Genetic → ISA )
Fussy
'
colony
Algorithm Optimization
new
(ANN)
( GA )
( Fi
)
( AC0)
particle
swarming
optimization
( PS0)
→ A meta - heuristic :
counter
generation
;
Let .
t=o → a
Plot ;
create & initiate a
population
repeat Pct ) ;
Hui
Evaluate the fitness ,
flu ;) ,
c-
Perform cross -
over
to produce offspring
Per for mutation on
offspring
select population
Pettis of new
geuez
.
generation + -1+1
the
=
new
Advance to ,
until
and "
is true :
stopping
- NP -
Complete Problems .
→
Applications :
detection
D concealed
weapon
controllers
e) Automotive
active
steering
.
→
Principles of G- A : based on two fundamentals
Genetics and Evolution
biological
:
process
is
→ G- d- Is a search heuristic that
inspired by
charles Darwin
theory of
natural evolution .
natural
process of
selection
the
→ It
reflects
individuals selected
where the fittest are
for reproduction
in order to produce
offspring
next
of the
gene
.
evolution
→
Abstraction of real
biological
( like NIP Hard)
→ solve complex problems
focus optimization
→
on
.
of possible sol a
problem .
will survive .
Encode .
-
Phenotype
-
Genotype
e
working
- :
Initialisation → chromosomes .
to
each chromosome In
↳ a score to
of generations
|
2) No .
.
reached Max
?
3) Performance stagnating ?
-
chromosome with higher value
to
.
I. Yes
✓ I
mutation
optimal crossover
✓
soi
f. 1
multi
single pt
pt .
* Evolution :
Natural selection :
* 4 premises
primary
:
D-
Information An
propagation
:
offspring has
in the next 2
gene
.
→
varsity )
3) existence
for Only
-
survival
: a small
produced
percentage of
the
offspring
survival to adulthood .
( selection )
4) survival
of the best
offspring survived
:
-
(
Ranking )
* selection :
selected to reproduce
→ the no .
of chromosomes
size
Keeping
size const
population
.
=
the .
→
This
phase has an element of randomness ,
↳ roulette -
wheel
↳
rank selection
↳
state
steady
-
,
etc .
To iuc selection
of
→
the
.
performance GA 's .
the
by elitc①which
methods are enhanced
method first
the
copies a few of
scored chromosomes
top &
to new population
then continues
the rest
of
generating
the population .
* Crossover :
Process bits
of chromosome
of combining
→
the one
single pt
-
crossover
.
P :
O l I 10
0
,
P2 :
I 1 0 I 00
01 ! 0 I 0 0
0 I
02 :
I 1 I 0 I 0
→ Two pt
.
cross over
P :
O l I 10
0
,
P2 :
I 1 0 I 00
< 2
I
01 ! 0 I 0 I 1 0
02 : I
I 1 0 0
0
- Multi pt
.
crossover :
Pi :
O l I 10
0
P2 :
I 1 0 I 00
Fr
~
swap K3
\
2
01 !
I 1 0
0 I 0
02 l
:
O l l O
0
crossover :
→ Uniform
the
At each bit position of parent
string ,
not .
will
swapping
be or
Rule ! If tou is 0
,
then
swap .
* mutation :
→
Performed after crossover
Sol in the
"
prevents
falling of
→ all
.
optimum of
solved
local
population ,
into a
problem
→ Mutation
changes
the new
offspring by
0 to 1
flipping
or
to 0
bits from 1
in the
→ Can occur at each bit position
string
with some
probability ,
usually
small
very
Eg offspring O
→ : :
l '
0 0 I
↳ crossover
Mutation MP ( Up ) :
O
O O 1
:
l O
probability
↳ mutation
Mutated MO : O O l O O O
offspring
Eg offspring 0
:
- :
I 1
0 0 I
* *
Mutated MO : 0 I 0 ? 1
offspring
* GA Operators :
with GA
fit
"
sd to
to
represent
a
D how
Encoding
:
framework .
2) the termination
Convergence how to decide
:
criteria
"
"
Granato generate
"
"" " "
of next son .
"
5) other Sol
Mutation explore
.
: to
to others
time
from
.
the
6) Inversion : to move op
?⃝
*
simple Genetic
Algorithm
:
: ; ÷-
÷
sta① -
Np is a subset of N
":_→;
µ
( population CN )
f
/
individual
each
( Evacuate pool (
randomly )
•
crou
⇐ ← Yes
£
IRep)
I
::;-n
with best fitness
to
s①
?⃝
value
'
'M
→
of depends on
programmer
.
*
sample F1
optimization problem
:
e) Portfolio optimization
e) Neural Network
Training
3) Design optimisation
4)
Drug Discovery
5) Traffic optimization
* GA Operators
:
encoding
Binary
__RedvaL encoding offertree
1) →
Encoding -
encoding
2) test
convergence
→
selected at
Pool A
mating pairare
3)
Mating
-
N then
→
of mating pool
is
Thus if size ,
random .
HE formed
meeting pains
are
4) → Fitness
5) → Evaluation
6) → Cross over
7) → Mutation
8) - Inversion
GA metaphor consisting of
* uses two
distinct element .
1-
Individual Population
-
defined by
a
chromosome .
stores
chromosome
info ( called phenotype)
genetic individual
for an
~
Genotype
Phenotype Is
4 set
The of
due actual
genes
representation
physical representing
the chromosome the
of
chromosome
* Real value
encoding
:
in continuous search
→ suitable for optimizing
space
.
&
→ avoid
any
intermediate
encoding decoding
Genotype y
- : a
-475.36
Phenotype 5.28
:
Order
encoding
:
*
Eg Tsp
→ :
creatingthe
is
* selection : It a
process for the
generation
current
Breeding
in
To population
generate
→ :
new
GA .
↳ create a
mating pool
↳ select a
pair
↳
Reproduce .
* selection involves
→
survival
of the fittest
existence
struggle for the
→ .
scheme is followed .
4) Tournament is selected
→
schemes individual
only
: → one
Np tournaments
evaluation ( fi ) tournament and
1) Canonical
- •
per
be played to
make the
%fg"÷hL!IE )
are to
5)
Roulette wheel steady
-
pool fitness
mating ✗
3) Rank -
based 6) Boltzmann
in
→ individuals are
assigned fitness
ascending order ace .
based selection
to .
- The