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

Notes

The document discusses algorithms for solving optimization and decision problems, focusing on backtracking and branch-and-bound methods. It explains the N-Queens problem, the Travelling Salesman Problem (TSP), and the Assignment Problem, highlighting their objectives and approaches. Additionally, it addresses the classification of problems into P, NP, NP-hard, and NP-complete categories, along with the significance of decision trees in data analysis.

Uploaded by

rakshaks.cs24
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views8 pages

Notes

The document discusses algorithms for solving optimization and decision problems, focusing on backtracking and branch-and-bound methods. It explains the N-Queens problem, the Travelling Salesman Problem (TSP), and the Assignment Problem, highlighting their objectives and approaches. Additionally, it addresses the classification of problems into P, NP, NP-hard, and NP-complete categories, along with the significance of decision trees in data analysis.

Uploaded by

rakshaks.cs24
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

UNI

Diff b w Branch Ee Bound Backtracking

Raacktracking Branch heBound

used to find all possible when it realises it already has a better


solutions available to a problem optimal soen that the pre sole leadsto it
when it realises that it has made a abandons that pre soen It completely searches
bad choice it undoesthe last choice the state space tree toget optimal soon
bybacking it up It searchesthe
state space tree until it has found It traves the tree in any manner
a soen
for the problem DFSor BFS

Backtracking traverses the state is used for solvingoptimisationproblem


space faceby DFS depth firstsearch
manner less efficient

used for solving decision problem useful in solving knapsackprob TSP

more efficient involves a boundingfine

useful for solving N queenproblem


sum of subset

involves a feasibility fun

SGSP
Backtracking NOP

N Queen's Problem

objective is to place n queens on a chessboard of dimension nxn such that notwo


queens attack each other whtqueen canattachrowwiseor column wiseor if they arediagonaltq
ouad
on

Einstein is gEtiiffeIii ai iii it


have
we can soen
another
Is tdthhtttwosoenstotxnn
aneenpnoseem IN
wht the 1stqueen can beplaced either intheIstcoe 2ndcoe 3rdor 4th

[Link]
E
I
[Link]

1stqueenincoe
Carearenotgettinganysour wekeep
if 1 sowewillbacktrackandmovethepositionofthe1staneen to andcoe

in thealg it ispretty complen to [Link] mathematical


eartobeusedin
in the alg we can take thetoll 2 cases

f man

I
abs F [Link] i

gamers
AlgorithmNdneens issue
11using backtracking thealg paints all possiblesoens

fori to n do
if place U i
CUT i 11peace1stqueen in particularcoeno
if k n
point x 1 n
else
Noveens Uti n 11findpossof [Link]
Algorithmplace K i
11returns Toureif Q is placed at 4ᵗʰ now and ith column otherwise autoonsfalse

return Tome
[Link] i e ei daiaoneaaaa

[Link]
iimanon negativeintegers 4.3.45 inputs
and'd willbe givethatis the man nal of subset
subsets 5 52 3output
The subsets should be derived from the set's such that sum of ele in the
subset d increasingorder
Shouldbe in

[Link]
ntEg
fft insane
Feynman If indeed

wewill
backache

53 8343
i 51 2 243and52 2353 andSs 3,45Long way
TimeComplexity
061 completeBinaryfree
sub [Link] hle i msaune
Algorithm Sung it
11 Ilp Keyshia holds the elements in increasingorder and dg
11 O P subsetswhosesummation is d
in
SEE
write x 1 no
elseif Stw D went d
sung sub StWRT Ktl 2 WED
d and StwCatB
if Sts WED
U u 0
d

sumofub S UH g w UD

TSP weuse DFS BFS Soin this wetranse


Branch and Bound A P inbothdirections

Assignment Problem

Objective is toassign n jobs to n'personssuch that the total cost of the


assignment is as smallaspossible
the A P is a lowerbound problem
LB is cal asthesumof leastnotin eachrow
6 T2 53 54

lb 2 3 1
1011
I
1547
as faite EEi iii iiE
Fliff
smallest
theft [Link]
[Link]
[Link]
[Link] P3Ftandh Tomasette
Sminusnere

FEE I
If
04 is
[Link]
assigned
huffy

to 54 mi
Travelling Salesman problem
the main objective of the TSP is to find a route such that a
salesperson visits allthe cities and returns back to the same cityfrom
where he started thetourwiththe min cost

TSP is a minimizationproblem hencewe are supposed to find the lowerbound

IB is 7 where s summation of 2 closestcities of a city forall cit


es 36
lb t
a 3m
If 141
2

a be the starting city


let

i
cityb is visited before city c

IEii [Link]
i
i
iiiiiii
i

iiiii
a

e
[Link] i

III
Iiiiiiiiiiiiiiiii
ii ii i

iii
iiiii
iiiiii
and
Iggy
nee in

É a

State Space Tall Is a tree each node represents a


representation where
state partialsoon toproblem and the branches represents
thepossible choices decisions that lead to the next state
Backtracking involvespruningthebranches that do not leadto a valid soen
NP hard and NP Complete problems
NP Non DeterministicAlg
0 p cannotbe predicted properly even if weknowthe IIP Same Ilp willgivediff outputsfor
diff rounds of execution

we non deterministic
alg
t L0 73 and a

in non det algs we cannot determine the next step of execution as


the alg will take more than onepath has 2 outputs
we will also get only approximate soens no accurate

the
Itstffffhf
same states
solns TT p the computer will always produce same outputgoingthrough

diff Ilp 120 deterministic


alg
diff o p q anda

PThffhat be solvedin
can
can be solved in time
polynomialtime is known as Pproblem
It pots using [Link] Linsearch Binsearch sortetz
significance problems in P are tractable or officiently solvable making them
practical for real world application

N P Problem
Problems that cannotbe solved in we are knownas N P problems
But they can be verifiable in polytime using non det algorithm For example
a probhastobesolvedin one hour If we solvetheprob within 1how givenpolynomialtimethen
isa P'problem If not it is an NP problem
Significance crucial asthey real world problems for which no
include many
efficientsoonalg is known The famous pvisNP question asks whether every
eneyprobwhosesoon canbe quicklyverified P canalsobequicklysolved P This
remains one of the most impopen questionsin computerscience

depending on Computingtime the Algs can beclassified


Polynomialtime algswhichtakeslesstimetocompletetheprob
ex linearsearch n binarysearch login insertionsort m mergesort nlogn matrin mult n
y
Exponentialtimealgswhichtakesmoretimeto evenif itis a small
1Unpsack 2n TSP 2n paob es2n
sumof subsets graphcoloring 2n hamiltonian cycle 2ny
Problems that do not needto be solvedin polytimecan be further classifiedinto 2
types

[Link]
prob which is Nphardand NP is knownas Complete problem
A problem that is N P Complete has the property that it can be solvedin
polynomialtime if onlyif all other N P complete problems can besolved in poly to

Attestscalled N P handif everyproblemin in NP can be polynomially reduced


If an NP hard problem can be solved in polynomial time then all NP complete
problems can be solvedin polyn time
CE A B C D N Pproblems
if all theseprobescan be reduced ton N PhardProblem

Decisintrees
popular and powerful tool used in various fieldssuch as
machine learning
data mining
statistics
They provide a clear intuitive way to make decisions basedon data bymodeling
the relationships b w diffvariables
Structure
Inode represents entire dataset initial decision
internal nodes reps decisions tests
leaf nodes reps final decisionprediction
Branches reps outcome of a decision testleading to another node

tʰÑ of comparisions in the worstcase is equal to the heightofthe alg's


decision tree
h2110s e
I Test imagethee
trees can be used
Decision foranalyzingworst 2 aug case efficienciesof Comparison BasedsortingAlgs
worst n Flogan

Cang n logan

You might also like